// Compiled by ClojureScript 1.10.520 {}
goog.provide('octet.spec.string');
goog.require('cljs.core');
goog.require('octet.buffer');
goog.require('octet.spec');
/**
 * Given a byte array, returns a number of bytes
 *   allocated with zero padding (zero byte).
 */
octet.spec.string.zeropad_count = (function octet$spec$string$zeropad_count(input){
var mark = (0);
return cljs.core.reduce.call(null,((function (mark){
return (function (sum,index){
var value = (input[index]);
if(cljs.core._EQ_.call(null,value,mark)){
return (sum + (1));
} else {
return cljs.core.reduced.call(null,sum);
}
});})(mark))
,(0),cljs.core.reverse.call(null,cljs.core.range.call(null,cljs.core.count.call(null,input))));
});
octet.spec.string.zeropad_BANG_ = (function octet$spec$string$zeropad_BANG_(input,datalength){
var seq__27460 = cljs.core.seq.call(null,cljs.core.range.call(null,input.length));
var chunk__27461 = null;
var count__27462 = (0);
var i__27463 = (0);
while(true){
if((i__27463 < count__27462)){
var i = cljs.core._nth.call(null,chunk__27461,i__27463);
if((i > datalength)){
(input[i] = (0));
} else {
}


var G__27468 = seq__27460;
var G__27469 = chunk__27461;
var G__27470 = count__27462;
var G__27471 = (i__27463 + (1));
seq__27460 = G__27468;
chunk__27461 = G__27469;
count__27462 = G__27470;
i__27463 = G__27471;
continue;
} else {
var temp__5720__auto__ = cljs.core.seq.call(null,seq__27460);
if(temp__5720__auto__){
var seq__27460__$1 = temp__5720__auto__;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__27460__$1)){
var c__4550__auto__ = cljs.core.chunk_first.call(null,seq__27460__$1);
var G__27472 = cljs.core.chunk_rest.call(null,seq__27460__$1);
var G__27473 = c__4550__auto__;
var G__27474 = cljs.core.count.call(null,c__4550__auto__);
var G__27475 = (0);
seq__27460 = G__27472;
chunk__27461 = G__27473;
count__27462 = G__27474;
i__27463 = G__27475;
continue;
} else {
var i = cljs.core.first.call(null,seq__27460__$1);
if((i > datalength)){
(input[i] = (0));
} else {
}


var G__27476 = cljs.core.next.call(null,seq__27460__$1);
var G__27477 = null;
var G__27478 = (0);
var G__27479 = (0);
seq__27460 = G__27476;
chunk__27461 = G__27477;
count__27462 = G__27478;
i__27463 = G__27479;
continue;
}
} else {
return null;
}
}
break;
}
});

octet.spec.string.bytes__GT_string = (function octet$spec$string$bytes__GT_string(input,length){
var view = input.subarray((0),length);
var view__$1 = (new Uint8Array(view));
var fcc = String.fromCharCode;
return fcc.apply(null,view__$1);
});

octet.spec.string.string__GT_bytes = (function octet$spec$string$string__GT_bytes(value){
var buff = (new ArrayBuffer(cljs.core.count.call(null,value)));
var view = (new Uint8Array(buff));
var seq__27464_27480 = cljs.core.seq.call(null,cljs.core.range.call(null,cljs.core.count.call(null,value)));
var chunk__27465_27481 = null;
var count__27466_27482 = (0);
var i__27467_27483 = (0);
while(true){
if((i__27467_27483 < count__27466_27482)){
var i_27484 = cljs.core._nth.call(null,chunk__27465_27481,i__27467_27483);
(view[i_27484] = value.charCodeAt(i_27484));


var G__27485 = seq__27464_27480;
var G__27486 = chunk__27465_27481;
var G__27487 = count__27466_27482;
var G__27488 = (i__27467_27483 + (1));
seq__27464_27480 = G__27485;
chunk__27465_27481 = G__27486;
count__27466_27482 = G__27487;
i__27467_27483 = G__27488;
continue;
} else {
var temp__5720__auto___27489 = cljs.core.seq.call(null,seq__27464_27480);
if(temp__5720__auto___27489){
var seq__27464_27490__$1 = temp__5720__auto___27489;
if(cljs.core.chunked_seq_QMARK_.call(null,seq__27464_27490__$1)){
var c__4550__auto___27491 = cljs.core.chunk_first.call(null,seq__27464_27490__$1);
var G__27492 = cljs.core.chunk_rest.call(null,seq__27464_27490__$1);
var G__27493 = c__4550__auto___27491;
var G__27494 = cljs.core.count.call(null,c__4550__auto___27491);
var G__27495 = (0);
seq__27464_27480 = G__27492;
chunk__27465_27481 = G__27493;
count__27466_27482 = G__27494;
i__27467_27483 = G__27495;
continue;
} else {
var i_27496 = cljs.core.first.call(null,seq__27464_27490__$1);
(view[i_27496] = value.charCodeAt(i_27496));


var G__27497 = cljs.core.next.call(null,seq__27464_27490__$1);
var G__27498 = null;
var G__27499 = (0);
var G__27500 = (0);
seq__27464_27480 = G__27497;
chunk__27465_27481 = G__27498;
count__27466_27482 = G__27499;
i__27467_27483 = G__27500;
continue;
}
} else {
}
}
break;
}

return (new Int8Array(buff));
});

octet.spec.string.arraycopy = (function octet$spec$string$arraycopy(input,output,length){
return cljs.core.reduce.call(null,(function (_,i){
return (output[i] = (input[i]));
}),null,cljs.core.range.call(null,input.length));
});

octet.spec.string.byte_array = (function octet$spec$string$byte_array(length){
return (new Int8Array(length));
});

Int8Array.prototype.cljs$core$ICounted$ = cljs.core.PROTOCOL_SENTINEL;

Int8Array.prototype.cljs$core$ICounted$_count$arity$1 = (function (s){
var s__$1 = this;
return s__$1.length;
});
/**
 * Fixed length string type spec constructor.
 */
octet.spec.string.string = (function octet$spec$string$string(size){
if((typeof octet !== 'undefined') && (typeof octet.spec !== 'undefined') && (typeof octet.spec.string !== 'undefined') && (typeof octet.spec.string.t_octet$spec$string27501 !== 'undefined')){
} else {

/**
* @constructor
 * @implements {octet.spec.ISpec}
 * @implements {cljs.core.IMeta}
 * @implements {cljs.core.IWithMeta}
 * @implements {octet.spec.ISpecSize}
*/
octet.spec.string.t_octet$spec$string27501 = (function (size,meta27502){
this.size = size;
this.meta27502 = meta27502;
this.cljs$lang$protocol_mask$partition0$ = 393216;
this.cljs$lang$protocol_mask$partition1$ = 0;
});
octet.spec.string.t_octet$spec$string27501.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (_27503,meta27502__$1){
var self__ = this;
var _27503__$1 = this;
return (new octet.spec.string.t_octet$spec$string27501(self__.size,meta27502__$1));
});

octet.spec.string.t_octet$spec$string27501.prototype.cljs$core$IMeta$_meta$arity$1 = (function (_27503){
var self__ = this;
var _27503__$1 = this;
return self__.meta27502;
});

octet.spec.string.t_octet$spec$string27501.prototype.octet$spec$ISpecSize$ = cljs.core.PROTOCOL_SENTINEL;

octet.spec.string.t_octet$spec$string27501.prototype.octet$spec$ISpecSize$size$arity$1 = (function (_){
var self__ = this;
var ___$1 = this;
return self__.size;
});

octet.spec.string.t_octet$spec$string27501.prototype.octet$spec$ISpec$ = cljs.core.PROTOCOL_SENTINEL;

octet.spec.string.t_octet$spec$string27501.prototype.octet$spec$ISpec$read$arity$3 = (function (_,buff,pos){
var self__ = this;
var ___$1 = this;
var rawdata = octet.buffer.read_bytes.call(null,buff,pos,self__.size);
var length = (self__.size - octet.spec.string.zeropad_count.call(null,rawdata));
var data = octet.spec.string.bytes__GT_string.call(null,rawdata,length);
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.size,data], null);
});

octet.spec.string.t_octet$spec$string27501.prototype.octet$spec$ISpec$write$arity$4 = (function (_,buff,pos,value){
var self__ = this;
var ___$1 = this;
var input = octet.spec.string.string__GT_bytes.call(null,value);
var length = cljs.core.count.call(null,input);
var tmpbuf = octet.spec.string.byte_array.call(null,self__.size);
if((length < self__.size)){
octet.spec.string.arraycopy.call(null,input,tmpbuf,length);
} else {
octet.spec.string.arraycopy.call(null,input,tmpbuf,self__.size);
}

if((length < self__.size)){
octet.spec.string.zeropad_BANG_.call(null,tmpbuf,length);
} else {
}

octet.buffer.write_bytes.call(null,buff,pos,self__.size,tmpbuf);

return self__.size;
});

octet.spec.string.t_octet$spec$string27501.getBasis = (function (){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"size","size",-1555742762,null),new cljs.core.Symbol(null,"meta27502","meta27502",-956939249,null)], null);
});

octet.spec.string.t_octet$spec$string27501.cljs$lang$type = true;

octet.spec.string.t_octet$spec$string27501.cljs$lang$ctorStr = "octet.spec.string/t_octet$spec$string27501";

octet.spec.string.t_octet$spec$string27501.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){
return cljs.core._write.call(null,writer__4375__auto__,"octet.spec.string/t_octet$spec$string27501");
});

/**
 * Positional factory function for octet.spec.string/t_octet$spec$string27501.
 */
octet.spec.string.__GT_t_octet$spec$string27501 = (function octet$spec$string$string_$___GT_t_octet$spec$string27501(size__$1,meta27502){
return (new octet.spec.string.t_octet$spec$string27501(size__$1,meta27502));
});

}

return (new octet.spec.string.t_octet$spec$string27501(size,cljs.core.PersistentArrayMap.EMPTY));
});
/**
 * Arbitrary length string type spec.
 */
octet.spec.string.string_STAR_ = (function (){
if((typeof octet !== 'undefined') && (typeof octet.spec !== 'undefined') && (typeof octet.spec.string !== 'undefined') && (typeof octet.spec.string.t_octet$spec$string27504 !== 'undefined')){
} else {

/**
* @constructor
 * @implements {cljs.core.IFn}
 * @implements {octet.spec.ISpecDynamicSize}
 * @implements {octet.spec.ISpec}
 * @implements {cljs.core.IMeta}
 * @implements {cljs.core.IWithMeta}
*/
octet.spec.string.t_octet$spec$string27504 = (function (meta27505){
this.meta27505 = meta27505;
this.cljs$lang$protocol_mask$partition0$ = 393217;
this.cljs$lang$protocol_mask$partition1$ = 0;
});
octet.spec.string.t_octet$spec$string27504.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (_27506,meta27505__$1){
var self__ = this;
var _27506__$1 = this;
return (new octet.spec.string.t_octet$spec$string27504(meta27505__$1));
});

octet.spec.string.t_octet$spec$string27504.prototype.cljs$core$IMeta$_meta$arity$1 = (function (_27506){
var self__ = this;
var _27506__$1 = this;
return self__.meta27505;
});

octet.spec.string.t_octet$spec$string27504.prototype.call = (function (self__){
var self__ = this;
var self____$1 = this;
var s = self____$1;
return s;
});

octet.spec.string.t_octet$spec$string27504.prototype.apply = (function (self__,args27507){
var self__ = this;
var self____$1 = this;
return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone.call(null,args27507)));
});

octet.spec.string.t_octet$spec$string27504.prototype.cljs$core$IFn$_invoke$arity$0 = (function (){
var self__ = this;
var s = this;
return s;
});

octet.spec.string.t_octet$spec$string27504.prototype.octet$spec$ISpecDynamicSize$ = cljs.core.PROTOCOL_SENTINEL;

octet.spec.string.t_octet$spec$string27504.prototype.octet$spec$ISpecDynamicSize$size_STAR_$arity$2 = (function (_,data){
var self__ = this;
var ___$1 = this;
var data__$1 = octet.spec.string.string__GT_bytes.call(null,data);
return ((4) + cljs.core.count.call(null,data__$1));
});

octet.spec.string.t_octet$spec$string27504.prototype.octet$spec$ISpec$ = cljs.core.PROTOCOL_SENTINEL;

octet.spec.string.t_octet$spec$string27504.prototype.octet$spec$ISpec$read$arity$3 = (function (_,buff,pos){
var self__ = this;
var ___$1 = this;
var datasize = octet.buffer.read_int.call(null,buff,pos);
var data = octet.buffer.read_bytes.call(null,buff,(pos + (4)),datasize);
var data__$1 = octet.spec.string.bytes__GT_string.call(null,data,datasize);
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [(datasize + (4)),data__$1], null);
});

octet.spec.string.t_octet$spec$string27504.prototype.octet$spec$ISpec$write$arity$4 = (function (_,buff,pos,value){
var self__ = this;
var ___$1 = this;
var input = octet.spec.string.string__GT_bytes.call(null,value);
var length = cljs.core.count.call(null,input);
octet.buffer.write_int.call(null,buff,pos,length);

octet.buffer.write_bytes.call(null,buff,(pos + (4)),length,input);

return (length + (4));
});

octet.spec.string.t_octet$spec$string27504.getBasis = (function (){
return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"meta27505","meta27505",-755153094,null)], null);
});

octet.spec.string.t_octet$spec$string27504.cljs$lang$type = true;

octet.spec.string.t_octet$spec$string27504.cljs$lang$ctorStr = "octet.spec.string/t_octet$spec$string27504";

octet.spec.string.t_octet$spec$string27504.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){
return cljs.core._write.call(null,writer__4375__auto__,"octet.spec.string/t_octet$spec$string27504");
});

/**
 * Positional factory function for octet.spec.string/t_octet$spec$string27504.
 */
octet.spec.string.__GT_t_octet$spec$string27504 = (function octet$spec$string$__GT_t_octet$spec$string27504(meta27505){
return (new octet.spec.string.t_octet$spec$string27504(meta27505));
});

}

return (new octet.spec.string.t_octet$spec$string27504(cljs.core.PersistentArrayMap.EMPTY));
})()
;
