// Compiled by ClojureScript 1.9.562 {}
goog.provide('octet.spec');
goog.require('cljs.core');
goog.require('octet.buffer');

/**
 * Basic abstraction for something that can be work like a Spec.
 * @interface
 */
octet.spec.ISpec = function(){};

/**
 * Read all data from buffer.
 */
octet.spec.read = (function octet$spec$read(_,buff,start){
if((!((_ == null))) && (!((_.octet$spec$ISpec$read$arity$3 == null)))){
return _.octet$spec$ISpec$read$arity$3(_,buff,start);
} else {
var x__23866__auto__ = (((_ == null))?null:_);
var m__23867__auto__ = (octet.spec.read[goog.typeOf(x__23866__auto__)]);
if(!((m__23867__auto__ == null))){
return m__23867__auto__.call(null,_,buff,start);
} else {
var m__23867__auto____$1 = (octet.spec.read["_"]);
if(!((m__23867__auto____$1 == null))){
return m__23867__auto____$1.call(null,_,buff,start);
} else {
throw cljs.core.missing_protocol.call(null,"ISpec.read",_);
}
}
}
});

/**
 * Read all data from buffer.
 */
octet.spec.write = (function octet$spec$write(_,buff,start,data){
if((!((_ == null))) && (!((_.octet$spec$ISpec$write$arity$4 == null)))){
return _.octet$spec$ISpec$write$arity$4(_,buff,start,data);
} else {
var x__23866__auto__ = (((_ == null))?null:_);
var m__23867__auto__ = (octet.spec.write[goog.typeOf(x__23866__auto__)]);
if(!((m__23867__auto__ == null))){
return m__23867__auto__.call(null,_,buff,start,data);
} else {
var m__23867__auto____$1 = (octet.spec.write["_"]);
if(!((m__23867__auto____$1 == null))){
return m__23867__auto____$1.call(null,_,buff,start,data);
} else {
throw cljs.core.missing_protocol.call(null,"ISpec.write",_);
}
}
}
});


/**
 * Abstraction for calculate size of static specs.
 * @interface
 */
octet.spec.ISpecSize = function(){};

/**
 * Calculate the size in bytes of the object.
 */
octet.spec.size = (function octet$spec$size(_){
if((!((_ == null))) && (!((_.octet$spec$ISpecSize$size$arity$1 == null)))){
return _.octet$spec$ISpecSize$size$arity$1(_);
} else {
var x__23866__auto__ = (((_ == null))?null:_);
var m__23867__auto__ = (octet.spec.size[goog.typeOf(x__23866__auto__)]);
if(!((m__23867__auto__ == null))){
return m__23867__auto__.call(null,_);
} else {
var m__23867__auto____$1 = (octet.spec.size["_"]);
if(!((m__23867__auto____$1 == null))){
return m__23867__auto____$1.call(null,_);
} else {
throw cljs.core.missing_protocol.call(null,"ISpecSize.size",_);
}
}
}
});


/**
 * Abstraction for calculate size for dynamic specs.
 * @interface
 */
octet.spec.ISpecDynamicSize = function(){};

/**
 * Calculate the size in bytes of the object having a data.
 */
octet.spec.size_STAR_ = (function octet$spec$size_STAR_(_,data){
if((!((_ == null))) && (!((_.octet$spec$ISpecDynamicSize$size_STAR_$arity$2 == null)))){
return _.octet$spec$ISpecDynamicSize$size_STAR_$arity$2(_,data);
} else {
var x__23866__auto__ = (((_ == null))?null:_);
var m__23867__auto__ = (octet.spec.size_STAR_[goog.typeOf(x__23866__auto__)]);
if(!((m__23867__auto__ == null))){
return m__23867__auto__.call(null,_,data);
} else {
var m__23867__auto____$1 = (octet.spec.size_STAR_["_"]);
if(!((m__23867__auto____$1 == null))){
return m__23867__auto____$1.call(null,_,data);
} else {
throw cljs.core.missing_protocol.call(null,"ISpecDynamicSize.size*",_);
}
}
}
});


/**
* @constructor
 * @implements {octet.spec.ISpecDynamicSize}
 * @implements {cljs.core.ICounted}
 * @implements {octet.spec.ISpec}
 * @implements {octet.spec.ISpecSize}
*/
octet.spec.AssociativeSpec = (function (data,dict,types){
this.data = data;
this.dict = dict;
this.types = types;
this.cljs$lang$protocol_mask$partition0$ = 2;
this.cljs$lang$protocol_mask$partition1$ = 0;
})
octet.spec.AssociativeSpec.prototype.cljs$core$ICounted$_count$arity$1 = (function (_){
var self__ = this;
var ___$1 = this;
return cljs.core.count.call(null,self__.types);
});

octet.spec.AssociativeSpec.prototype.octet$spec$ISpecSize$ = cljs.core.PROTOCOL_SENTINEL;

octet.spec.AssociativeSpec.prototype.octet$spec$ISpecSize$size$arity$1 = (function (_){
var self__ = this;
var ___$1 = this;
return cljs.core.reduce.call(null,((function (___$1){
return (function (p1__34320_SHARP_,p2__34321_SHARP_){
return (p1__34320_SHARP_ + octet.spec.size.call(null,p2__34321_SHARP_));
});})(___$1))
,(0),self__.types);
});

octet.spec.AssociativeSpec.prototype.octet$spec$ISpecDynamicSize$ = cljs.core.PROTOCOL_SENTINEL;

octet.spec.AssociativeSpec.prototype.octet$spec$ISpecDynamicSize$size_STAR_$arity$2 = (function (_,data__$1){
var self__ = this;
var ___$1 = this;
return cljs.core.reduce.call(null,((function (___$1){
return (function (acc,p__34322){
var vec__34323 = p__34322;
var field = cljs.core.nth.call(null,vec__34323,(0),null);
var data__$2 = cljs.core.nth.call(null,vec__34323,(1),null);
var type = field.call(null,self__.dict);
if(((!((type == null)))?(((false) || ((cljs.core.PROTOCOL_SENTINEL === type.octet$spec$ISpecSize$)))?true:(((!type.cljs$lang$protocol_mask$partition$))?cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecSize,type):false)):cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecSize,type))){
return (acc + octet.spec.size.call(null,type));
} else {
return (acc + octet.spec.size_STAR_.call(null,type,data__$2));
}
});})(___$1))
,(0),cljs.core.into.call(null,cljs.core.PersistentVector.EMPTY,data__$1));
});

octet.spec.AssociativeSpec.prototype.octet$spec$ISpec$ = cljs.core.PROTOCOL_SENTINEL;

octet.spec.AssociativeSpec.prototype.octet$spec$ISpec$read$arity$3 = (function (_,buff,pos){
var self__ = this;
var ___$1 = this;
var index = pos;
var result = cljs.core.PersistentArrayMap.EMPTY;
var pairs = self__.data;
while(true){
var temp__5276__auto__ = cljs.core.first.call(null,pairs);
if(cljs.core.truth_(temp__5276__auto__)){
var vec__34327 = temp__5276__auto__;
var fieldname = cljs.core.nth.call(null,vec__34327,(0),null);
var type = cljs.core.nth.call(null,vec__34327,(1),null);
var vec__34330 = octet.spec.read.call(null,type,buff,index);
var readedbytes = cljs.core.nth.call(null,vec__34330,(0),null);
var readeddata = cljs.core.nth.call(null,vec__34330,(1),null);
var G__34337 = (index + readedbytes);
var G__34338 = cljs.core.assoc.call(null,result,fieldname,readeddata);
var G__34339 = cljs.core.rest.call(null,pairs);
index = G__34337;
result = G__34338;
pairs = G__34339;
continue;
} else {
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [(index - pos),result], null);
}
break;
}
});

octet.spec.AssociativeSpec.prototype.octet$spec$ISpec$write$arity$4 = (function (_,buff,pos,data_SINGLEQUOTE_){
var self__ = this;
var ___$1 = this;
var written = cljs.core.reduce.call(null,((function (___$1){
return (function (index,p__34333){
var vec__34334 = p__34333;
var fieldname = cljs.core.nth.call(null,vec__34334,(0),null);
var type = cljs.core.nth.call(null,vec__34334,(1),null);
var value = cljs.core.get.call(null,data_SINGLEQUOTE_,fieldname,null);
var written = octet.spec.write.call(null,type,buff,index,value);
return (index + written);
});})(___$1))
,pos,self__.data);
return (written - pos);
});

octet.spec.AssociativeSpec.getBasis = (function (){
return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"data","data",1407862150,null),new cljs.core.Symbol(null,"dict","dict",10567054,null),new cljs.core.Symbol(null,"types","types",-2064405130,null)], null);
});

octet.spec.AssociativeSpec.cljs$lang$type = true;

octet.spec.AssociativeSpec.cljs$lang$ctorStr = "octet.spec/AssociativeSpec";

octet.spec.AssociativeSpec.cljs$lang$ctorPrWriter = (function (this__23805__auto__,writer__23806__auto__,opt__23807__auto__){
return cljs.core._write.call(null,writer__23806__auto__,"octet.spec/AssociativeSpec");
});

octet.spec.__GT_AssociativeSpec = (function octet$spec$__GT_AssociativeSpec(data,dict,types){
return (new octet.spec.AssociativeSpec(data,dict,types));
});


/**
* @constructor
 * @implements {octet.spec.ISpecDynamicSize}
 * @implements {cljs.core.ICounted}
 * @implements {octet.spec.ISpec}
 * @implements {octet.spec.ISpecSize}
*/
octet.spec.IndexedSpec = (function (types){
this.types = types;
this.cljs$lang$protocol_mask$partition0$ = 2;
this.cljs$lang$protocol_mask$partition1$ = 0;
})
octet.spec.IndexedSpec.prototype.cljs$core$ICounted$_count$arity$1 = (function (_){
var self__ = this;
var ___$1 = this;
return cljs.core.count.call(null,self__.types);
});

octet.spec.IndexedSpec.prototype.octet$spec$ISpecSize$ = cljs.core.PROTOCOL_SENTINEL;

octet.spec.IndexedSpec.prototype.octet$spec$ISpecSize$size$arity$1 = (function (_){
var self__ = this;
var ___$1 = this;
return cljs.core.reduce.call(null,((function (___$1){
return (function (p1__34340_SHARP_,p2__34341_SHARP_){
return (p1__34340_SHARP_ + octet.spec.size.call(null,p2__34341_SHARP_));
});})(___$1))
,(0),self__.types);
});

octet.spec.IndexedSpec.prototype.octet$spec$ISpecDynamicSize$ = cljs.core.PROTOCOL_SENTINEL;

octet.spec.IndexedSpec.prototype.octet$spec$ISpecDynamicSize$size_STAR_$arity$2 = (function (_,data){
var self__ = this;
var ___$1 = this;
return cljs.core.reduce.call(null,((function (___$1){
return (function (acc,p__34342){
var vec__34343 = p__34342;
var index = cljs.core.nth.call(null,vec__34343,(0),null);
var data__$1 = cljs.core.nth.call(null,vec__34343,(1),null);
var type = cljs.core.nth.call(null,self__.types,index);
if(((!((type == null)))?(((false) || ((cljs.core.PROTOCOL_SENTINEL === type.octet$spec$ISpecSize$)))?true:(((!type.cljs$lang$protocol_mask$partition$))?cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecSize,type):false)):cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecSize,type))){
return (acc + octet.spec.size.call(null,type));
} else {
return (acc + octet.spec.size_STAR_.call(null,type,data__$1));
}
});})(___$1))
,(0),cljs.core.map_indexed.call(null,cljs.core.vector,data));
});

octet.spec.IndexedSpec.prototype.octet$spec$ISpec$ = cljs.core.PROTOCOL_SENTINEL;

octet.spec.IndexedSpec.prototype.octet$spec$ISpec$read$arity$3 = (function (_,buff,pos){
var self__ = this;
var ___$1 = this;
var index = pos;
var result = cljs.core.PersistentVector.EMPTY;
var types__$1 = self__.types;
while(true){
var temp__5276__auto__ = cljs.core.first.call(null,types__$1);
if(cljs.core.truth_(temp__5276__auto__)){
var type = temp__5276__auto__;
var vec__34347 = octet.spec.read.call(null,type,buff,index);
var readedbytes = cljs.core.nth.call(null,vec__34347,(0),null);
var readeddata = cljs.core.nth.call(null,vec__34347,(1),null);
var G__34354 = (index + readedbytes);
var G__34355 = cljs.core.conj.call(null,result,readeddata);
var G__34356 = cljs.core.rest.call(null,types__$1);
index = G__34354;
result = G__34355;
types__$1 = G__34356;
continue;
} else {
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [(index - pos),result], null);
}
break;
}
});

octet.spec.IndexedSpec.prototype.octet$spec$ISpec$write$arity$4 = (function (_,buff,pos,data_SINGLEQUOTE_){
var self__ = this;
var ___$1 = this;
var indexedtypes = cljs.core.map_indexed.call(null,cljs.core.vector,self__.types);
var written = cljs.core.reduce.call(null,((function (indexedtypes,___$1){
return (function (pos__$1,p__34350){
var vec__34351 = p__34350;
var index = cljs.core.nth.call(null,vec__34351,(0),null);
var type = cljs.core.nth.call(null,vec__34351,(1),null);
var value = cljs.core.nth.call(null,data_SINGLEQUOTE_,index,null);
var written = octet.spec.write.call(null,type,buff,pos__$1,value);
return (pos__$1 + written);
});})(indexedtypes,___$1))
,pos,indexedtypes);
return (written - pos);
});

octet.spec.IndexedSpec.getBasis = (function (){
return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"types","types",-2064405130,null)], null);
});

octet.spec.IndexedSpec.cljs$lang$type = true;

octet.spec.IndexedSpec.cljs$lang$ctorStr = "octet.spec/IndexedSpec";

octet.spec.IndexedSpec.cljs$lang$ctorPrWriter = (function (this__23805__auto__,writer__23806__auto__,opt__23807__auto__){
return cljs.core._write.call(null,writer__23806__auto__,"octet.spec/IndexedSpec");
});

octet.spec.__GT_IndexedSpec = (function octet$spec$__GT_IndexedSpec(types){
return (new octet.spec.IndexedSpec(types));
});

octet.spec.associative_spec = (function octet$spec$associative_spec(var_args){
var args__24376__auto__ = [];
var len__24369__auto___34358 = arguments.length;
var i__24370__auto___34359 = (0);
while(true){
if((i__24370__auto___34359 < len__24369__auto___34358)){
args__24376__auto__.push((arguments[i__24370__auto___34359]));

var G__34360 = (i__24370__auto___34359 + (1));
i__24370__auto___34359 = G__34360;
continue;
} else {
}
break;
}

var argseq__24377__auto__ = ((((0) < args__24376__auto__.length))?(new cljs.core.IndexedSeq(args__24376__auto__.slice((0)),(0),null)):null);
return octet.spec.associative_spec.cljs$core$IFn$_invoke$arity$variadic(argseq__24377__auto__);
});

octet.spec.associative_spec.cljs$core$IFn$_invoke$arity$variadic = (function (params){
var data = cljs.core.mapv.call(null,cljs.core.vec,cljs.core.partition.call(null,(2),params));
var dict = cljs.core.into.call(null,cljs.core.PersistentArrayMap.EMPTY,data);
var types = cljs.core.map.call(null,cljs.core.second,data);
return (new octet.spec.AssociativeSpec(data,dict,types));
});

octet.spec.associative_spec.cljs$lang$maxFixedArity = (0);

octet.spec.associative_spec.cljs$lang$applyTo = (function (seq34357){
return octet.spec.associative_spec.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq34357));
});

octet.spec.indexed_spec = (function octet$spec$indexed_spec(var_args){
var args__24376__auto__ = [];
var len__24369__auto___34362 = arguments.length;
var i__24370__auto___34363 = (0);
while(true){
if((i__24370__auto___34363 < len__24369__auto___34362)){
args__24376__auto__.push((arguments[i__24370__auto___34363]));

var G__34364 = (i__24370__auto___34363 + (1));
i__24370__auto___34363 = G__34364;
continue;
} else {
}
break;
}

var argseq__24377__auto__ = ((((0) < args__24376__auto__.length))?(new cljs.core.IndexedSeq(args__24376__auto__.slice((0)),(0),null)):null);
return octet.spec.indexed_spec.cljs$core$IFn$_invoke$arity$variadic(argseq__24377__auto__);
});

octet.spec.indexed_spec.cljs$core$IFn$_invoke$arity$variadic = (function (types){
return (new octet.spec.IndexedSpec(types));
});

octet.spec.indexed_spec.cljs$lang$maxFixedArity = (0);

octet.spec.indexed_spec.cljs$lang$applyTo = (function (seq34361){
return octet.spec.indexed_spec.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq34361));
});

/**
 * Polymorphic constructor for Spec instances.
 * 
 *   Spec is a some kind of composition of arbitrary
 *   number of types in associative or indexed data
 *   structure.
 * 
 *   Little example on how to create associative
 *   composition:
 * 
 *    (spec :field1 (long)
 *          :field2 (string 20))
 * 
 *   An other example on how to create indexed
 *   composition that represents the same bytes
 *   representation that previous one:
 * 
 *    (spec (long) (string 20))
 * 
 *   The main difference between the two reprensentation
 *   is that if you read a buffer using an associative
 *   spec, the result will be clojure hash-map, and if
 *   indexed spec is used, the result will be clojure
 *   vector containing the values.
 * 
 *   The same rules applies for writing data into a
 *   buffer.
 */
octet.spec.spec = (function octet$spec$spec(var_args){
var args__24376__auto__ = [];
var len__24369__auto___34371 = arguments.length;
var i__24370__auto___34372 = (0);
while(true){
if((i__24370__auto___34372 < len__24369__auto___34371)){
args__24376__auto__.push((arguments[i__24370__auto___34372]));

var G__34373 = (i__24370__auto___34372 + (1));
i__24370__auto___34372 = G__34373;
continue;
} else {
}
break;
}

var argseq__24377__auto__ = ((((0) < args__24376__auto__.length))?(new cljs.core.IndexedSeq(args__24376__auto__.slice((0)),(0),null)):null);
return octet.spec.spec.cljs$core$IFn$_invoke$arity$variadic(argseq__24377__auto__);
});

octet.spec.spec.cljs$core$IFn$_invoke$arity$variadic = (function (params){
var numparams = cljs.core.count.call(null,params);
if(cljs.core.every_QMARK_.call(null,((function (numparams){
return (function (p1__34365_SHARP_){
if(!((p1__34365_SHARP_ == null))){
if((false) || ((cljs.core.PROTOCOL_SENTINEL === p1__34365_SHARP_.octet$spec$ISpec$))){
return true;
} else {
if((!p1__34365_SHARP_.cljs$lang$protocol_mask$partition$)){
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,p1__34365_SHARP_);
} else {
return false;
}
}
} else {
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,p1__34365_SHARP_);
}
});})(numparams))
,params)){
return cljs.core.apply.call(null,octet.spec.indexed_spec,params);
} else {
if((function (){var and__23136__auto__ = cljs.core.even_QMARK_.call(null,numparams);
if(and__23136__auto__){
var and__23136__auto____$1 = (cljs.core.first.call(null,params) instanceof cljs.core.Keyword);
if(and__23136__auto____$1){
var G__34370 = cljs.core.second.call(null,params);
if(!((G__34370 == null))){
if((false) || ((cljs.core.PROTOCOL_SENTINEL === G__34370.octet$spec$ISpec$))){
return true;
} else {
if((!G__34370.cljs$lang$protocol_mask$partition$)){
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,G__34370);
} else {
return false;
}
}
} else {
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,G__34370);
}
} else {
return and__23136__auto____$1;
}
} else {
return and__23136__auto__;
}
})()){
return cljs.core.apply.call(null,octet.spec.associative_spec,params);
} else {
throw cljs.core.ex_info.call(null,"Invalid arguments",cljs.core.PersistentArrayMap.EMPTY);

}
}
});

octet.spec.spec.cljs$lang$maxFixedArity = (0);

octet.spec.spec.cljs$lang$applyTo = (function (seq34366){
return octet.spec.spec.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq34366));
});

/**
 * Creare a composed typespec that repeats `n` times
 *   a provided `type` spec.
 * 
 *   As example, create a spec with help of `repeat`
 *   function:
 * 
 *    (def spec (buf/repeat 2 buf/int32))
 * 
 *   Write data into buffer using previously defined
 *   typespec:
 * 
 *    (buf/write! yourbuffer [200 300] spec)
 *    ;; => 8
 * 
 *   Or read data from your buffer using previously defined
 *   typespec:
 * 
 *    (buf/read yourbuffer spec)
 *    ;; => [200 300]
 *   
 */
octet.spec.repeat = (function octet$spec$repeat(n,type){
if(typeof octet.spec.t_octet$spec34385 !== 'undefined'){
} else {

/**
* @constructor
 * @implements {octet.spec.ISpecDynamicSize}
 * @implements {octet.spec.ISpec}
 * @implements {cljs.core.IMeta}
 * @implements {cljs.core.IWithMeta}
 * @implements {octet.spec.ISpecSize}
*/
octet.spec.t_octet$spec34385 = (function (n,type,meta34386){
this.n = n;
this.type = type;
this.meta34386 = meta34386;
this.cljs$lang$protocol_mask$partition0$ = 393216;
this.cljs$lang$protocol_mask$partition1$ = 0;
})
octet.spec.t_octet$spec34385.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (_34387,meta34386__$1){
var self__ = this;
var _34387__$1 = this;
return (new octet.spec.t_octet$spec34385(self__.n,self__.type,meta34386__$1));
});

octet.spec.t_octet$spec34385.prototype.cljs$core$IMeta$_meta$arity$1 = (function (_34387){
var self__ = this;
var _34387__$1 = this;
return self__.meta34386;
});

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

octet.spec.t_octet$spec34385.prototype.octet$spec$ISpecSize$size$arity$1 = (function (_){
var self__ = this;
var ___$1 = this;
return (self__.n * octet.spec.size.call(null,self__.type));
});

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

octet.spec.t_octet$spec34385.prototype.octet$spec$ISpecDynamicSize$size_STAR_$arity$2 = (function (_,data){
var self__ = this;
var ___$1 = this;
return cljs.core.reduce.call(null,((function (___$1){
return (function (acc,p__34388){
var vec__34389 = p__34388;
var index = cljs.core.nth.call(null,vec__34389,(0),null);
var data__$1 = cljs.core.nth.call(null,vec__34389,(1),null);
if(((!((self__.type == null)))?(((false) || ((cljs.core.PROTOCOL_SENTINEL === self__.type.octet$spec$ISpecSize$)))?true:(((!self__.type.cljs$lang$protocol_mask$partition$))?cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecSize,self__.type):false)):cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecSize,self__.type))){
return (acc + octet.spec.size.call(null,self__.type));
} else {
return (acc + octet.spec.size_STAR_.call(null,self__.type,data__$1));
}
});})(___$1))
,(0),cljs.core.map_indexed.call(null,cljs.core.vector,data));
});

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

octet.spec.t_octet$spec34385.prototype.octet$spec$ISpec$read$arity$3 = (function (_,buff,pos){
var self__ = this;
var ___$1 = this;
var index = pos;
var result = cljs.core.PersistentVector.EMPTY;
var types = cljs.core.take.call(null,self__.n,cljs.core.repeatedly.call(null,cljs.core.constantly.call(null,self__.type)));
while(true){
var temp__5276__auto__ = cljs.core.first.call(null,types);
if(cljs.core.truth_(temp__5276__auto__)){
var type__$1 = temp__5276__auto__;
var vec__34393 = octet.spec.read.call(null,type__$1,buff,index);
var readedbytes = cljs.core.nth.call(null,vec__34393,(0),null);
var readeddata = cljs.core.nth.call(null,vec__34393,(1),null);
var G__34396 = (index + readedbytes);
var G__34397 = cljs.core.conj.call(null,result,readeddata);
var G__34398 = cljs.core.rest.call(null,types);
index = G__34396;
result = G__34397;
types = G__34398;
continue;
} else {
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [(index - pos),result], null);
}
break;
}
});

octet.spec.t_octet$spec34385.prototype.octet$spec$ISpec$write$arity$4 = (function (_,buff,pos,data){
var self__ = this;
var ___$1 = this;
var data__$1 = data;
var written = pos;
while(true){
var temp__5276__auto__ = cljs.core.first.call(null,data__$1);
if(cljs.core.truth_(temp__5276__auto__)){
var value = temp__5276__auto__;
var written_SINGLEQUOTE_ = octet.spec.write.call(null,self__.type,buff,written,value);
var G__34399 = cljs.core.rest.call(null,data__$1);
var G__34400 = (written + written_SINGLEQUOTE_);
data__$1 = G__34399;
written = G__34400;
continue;
} else {
return (written - pos);
}
break;
}
});

octet.spec.t_octet$spec34385.getBasis = (function (){
return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"n","n",-2092305744,null),new cljs.core.Symbol(null,"type","type",-1480165421,null),new cljs.core.Symbol(null,"meta34386","meta34386",-1998832075,null)], null);
});

octet.spec.t_octet$spec34385.cljs$lang$type = true;

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

octet.spec.t_octet$spec34385.cljs$lang$ctorPrWriter = (function (this__23805__auto__,writer__23806__auto__,opt__23807__auto__){
return cljs.core._write.call(null,writer__23806__auto__,"octet.spec/t_octet$spec34385");
});

octet.spec.__GT_t_octet$spec34385 = (function octet$spec$repeat_$___GT_t_octet$spec34385(n__$1,type__$1,meta34386){
return (new octet.spec.t_octet$spec34385(n__$1,type__$1,meta34386));
});

}

return (new octet.spec.t_octet$spec34385(n,type,cljs.core.PersistentArrayMap.EMPTY));
});
/**
 * Create a composed typespec with user defined
 *   type constructor.
 * 
 *   This allows define a typespec with automatic conversion
 *   between user data type and serialized data without
 *   defining yourself a datatype using low level constructions.
 * 
 *   Let see an exameple for understand it better.
 * 
 *   Imagine you are have this data type:
 * 
 *    (defrecord Point [x y])
 * 
 *   With help of `compose`, create a new spec
 *   for your datatype:
 * 
 *    (def point-spec (buf/compose ->Point [buf/int32 buf/int32]))
 * 
 *   Now, you can use the previously defined datatype and typespec
 *   for write into buffer:
 * 
 *    (buf/write! buffer mypoint point-spec)
 *    ;; => 8
 * 
 *   Or read from the buffer:
 * 
 *    (buf/read buffer (point))
 *    ;; => #user.Point{:x 1, :y 2}
 *   
 */
octet.spec.compose = (function octet$spec$compose(constructor$,types){
if(cljs.core.fn_QMARK_.call(null,constructor$)){
} else {
throw (new Error("Assert failed: (fn? constructor)"));
}

if(cljs.core.vector_QMARK_.call(null,types)){
} else {
throw (new Error("Assert failed: (vector? types)"));
}

var spec_SINGLEQUOTE_ = cljs.core.apply.call(null,octet.spec.spec,types);
if(typeof octet.spec.t_octet$spec34407 !== 'undefined'){
} else {

/**
* @constructor
 * @implements {octet.spec.ISpec}
 * @implements {cljs.core.IMeta}
 * @implements {cljs.core.IWithMeta}
 * @implements {octet.spec.ISpecSize}
*/
octet.spec.t_octet$spec34407 = (function (constructor$,types,spec_SINGLEQUOTE_,meta34408){
this.constructor$ = constructor$;
this.types = types;
this.spec_SINGLEQUOTE_ = spec_SINGLEQUOTE_;
this.meta34408 = meta34408;
this.cljs$lang$protocol_mask$partition0$ = 393216;
this.cljs$lang$protocol_mask$partition1$ = 0;
})
octet.spec.t_octet$spec34407.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = ((function (spec_SINGLEQUOTE_){
return (function (_34409,meta34408__$1){
var self__ = this;
var _34409__$1 = this;
return (new octet.spec.t_octet$spec34407(self__.constructor$,self__.types,self__.spec_SINGLEQUOTE_,meta34408__$1));
});})(spec_SINGLEQUOTE_))
;

octet.spec.t_octet$spec34407.prototype.cljs$core$IMeta$_meta$arity$1 = ((function (spec_SINGLEQUOTE_){
return (function (_34409){
var self__ = this;
var _34409__$1 = this;
return self__.meta34408;
});})(spec_SINGLEQUOTE_))
;

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

octet.spec.t_octet$spec34407.prototype.octet$spec$ISpecSize$size$arity$1 = ((function (spec_SINGLEQUOTE_){
return (function (_){
var self__ = this;
var ___$1 = this;
return octet.spec.size.call(null,self__.spec_SINGLEQUOTE_);
});})(spec_SINGLEQUOTE_))
;

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

octet.spec.t_octet$spec34407.prototype.octet$spec$ISpec$read$arity$3 = ((function (spec_SINGLEQUOTE_){
return (function (_,buff,pos){
var self__ = this;
var ___$1 = this;
var vec__34410 = octet.spec.read.call(null,self__.spec_SINGLEQUOTE_,buff,pos);
var readed = cljs.core.nth.call(null,vec__34410,(0),null);
var data = cljs.core.nth.call(null,vec__34410,(1),null);
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [readed,cljs.core.apply.call(null,self__.constructor$,data)], null);
});})(spec_SINGLEQUOTE_))
;

octet.spec.t_octet$spec34407.prototype.octet$spec$ISpec$write$arity$4 = ((function (spec_SINGLEQUOTE_){
return (function (_,buff,pos,data_SINGLEQUOTE_){
var self__ = this;
var ___$1 = this;
var data_SINGLEQUOTE___$1 = cljs.core.vec.call(null,cljs.core.vals.call(null,data_SINGLEQUOTE_));
return octet.spec.write.call(null,self__.spec_SINGLEQUOTE_,buff,pos,data_SINGLEQUOTE___$1);
});})(spec_SINGLEQUOTE_))
;

octet.spec.t_octet$spec34407.getBasis = ((function (spec_SINGLEQUOTE_){
return (function (){
return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"constructor","constructor",-313397284,null),new cljs.core.Symbol(null,"types","types",-2064405130,null),new cljs.core.Symbol(null,"spec'","spec'",-1719556456,null),new cljs.core.Symbol(null,"meta34408","meta34408",-57507363,null)], null);
});})(spec_SINGLEQUOTE_))
;

octet.spec.t_octet$spec34407.cljs$lang$type = true;

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

octet.spec.t_octet$spec34407.cljs$lang$ctorPrWriter = ((function (spec_SINGLEQUOTE_){
return (function (this__23805__auto__,writer__23806__auto__,opt__23807__auto__){
return cljs.core._write.call(null,writer__23806__auto__,"octet.spec/t_octet$spec34407");
});})(spec_SINGLEQUOTE_))
;

octet.spec.__GT_t_octet$spec34407 = ((function (spec_SINGLEQUOTE_){
return (function octet$spec$compose_$___GT_t_octet$spec34407(constructor$__$1,types__$1,spec_SINGLEQUOTE___$1,meta34408){
return (new octet.spec.t_octet$spec34407(constructor$__$1,types__$1,spec_SINGLEQUOTE___$1,meta34408));
});})(spec_SINGLEQUOTE_))
;

}

return (new octet.spec.t_octet$spec34407(constructor$,types,spec_SINGLEQUOTE_,cljs.core.PersistentArrayMap.EMPTY));
});
