// 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__24056__auto__ = (((_ == null))?null:_);
var m__24057__auto__ = (octet.spec.read[goog.typeOf(x__24056__auto__)]);
if(!((m__24057__auto__ == null))){
return m__24057__auto__.call(null,_,buff,start);
} else {
var m__24057__auto____$1 = (octet.spec.read["_"]);
if(!((m__24057__auto____$1 == null))){
return m__24057__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__24056__auto__ = (((_ == null))?null:_);
var m__24057__auto__ = (octet.spec.write[goog.typeOf(x__24056__auto__)]);
if(!((m__24057__auto__ == null))){
return m__24057__auto__.call(null,_,buff,start,data);
} else {
var m__24057__auto____$1 = (octet.spec.write["_"]);
if(!((m__24057__auto____$1 == null))){
return m__24057__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__24056__auto__ = (((_ == null))?null:_);
var m__24057__auto__ = (octet.spec.size[goog.typeOf(x__24056__auto__)]);
if(!((m__24057__auto__ == null))){
return m__24057__auto__.call(null,_);
} else {
var m__24057__auto____$1 = (octet.spec.size["_"]);
if(!((m__24057__auto____$1 == null))){
return m__24057__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__24056__auto__ = (((_ == null))?null:_);
var m__24057__auto__ = (octet.spec.size_STAR_[goog.typeOf(x__24056__auto__)]);
if(!((m__24057__auto__ == null))){
return m__24057__auto__.call(null,_,data);
} else {
var m__24057__auto____$1 = (octet.spec.size_STAR_["_"]);
if(!((m__24057__auto____$1 == null))){
return m__24057__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__34155_SHARP_,p2__34156_SHARP_){
return (p1__34155_SHARP_ + octet.spec.size.call(null,p2__34156_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__34157){
var vec__34158 = p__34157;
var field = cljs.core.nth.call(null,vec__34158,(0),null);
var data__$2 = cljs.core.nth.call(null,vec__34158,(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__34162 = temp__5276__auto__;
var fieldname = cljs.core.nth.call(null,vec__34162,(0),null);
var type = cljs.core.nth.call(null,vec__34162,(1),null);
var vec__34165 = octet.spec.read.call(null,type,buff,index);
var readedbytes = cljs.core.nth.call(null,vec__34165,(0),null);
var readeddata = cljs.core.nth.call(null,vec__34165,(1),null);
var G__34172 = (index + readedbytes);
var G__34173 = cljs.core.assoc.call(null,result,fieldname,readeddata);
var G__34174 = cljs.core.rest.call(null,pairs);
index = G__34172;
result = G__34173;
pairs = G__34174;
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__34168){
var vec__34169 = p__34168;
var fieldname = cljs.core.nth.call(null,vec__34169,(0),null);
var type = cljs.core.nth.call(null,vec__34169,(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__23995__auto__,writer__23996__auto__,opt__23997__auto__){
return cljs.core._write.call(null,writer__23996__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__34175_SHARP_,p2__34176_SHARP_){
return (p1__34175_SHARP_ + octet.spec.size.call(null,p2__34176_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__34177){
var vec__34178 = p__34177;
var index = cljs.core.nth.call(null,vec__34178,(0),null);
var data__$1 = cljs.core.nth.call(null,vec__34178,(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__34182 = octet.spec.read.call(null,type,buff,index);
var readedbytes = cljs.core.nth.call(null,vec__34182,(0),null);
var readeddata = cljs.core.nth.call(null,vec__34182,(1),null);
var G__34189 = (index + readedbytes);
var G__34190 = cljs.core.conj.call(null,result,readeddata);
var G__34191 = cljs.core.rest.call(null,types__$1);
index = G__34189;
result = G__34190;
types__$1 = G__34191;
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__34185){
var vec__34186 = p__34185;
var index = cljs.core.nth.call(null,vec__34186,(0),null);
var type = cljs.core.nth.call(null,vec__34186,(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__23995__auto__,writer__23996__auto__,opt__23997__auto__){
return cljs.core._write.call(null,writer__23996__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__24566__auto__ = [];
var len__24559__auto___34193 = arguments.length;
var i__24560__auto___34194 = (0);
while(true){
if((i__24560__auto___34194 < len__24559__auto___34193)){
args__24566__auto__.push((arguments[i__24560__auto___34194]));

var G__34195 = (i__24560__auto___34194 + (1));
i__24560__auto___34194 = G__34195;
continue;
} else {
}
break;
}

var argseq__24567__auto__ = ((((0) < args__24566__auto__.length))?(new cljs.core.IndexedSeq(args__24566__auto__.slice((0)),(0),null)):null);
return octet.spec.associative_spec.cljs$core$IFn$_invoke$arity$variadic(argseq__24567__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 (seq34192){
return octet.spec.associative_spec.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq34192));
});

octet.spec.indexed_spec = (function octet$spec$indexed_spec(var_args){
var args__24566__auto__ = [];
var len__24559__auto___34197 = arguments.length;
var i__24560__auto___34198 = (0);
while(true){
if((i__24560__auto___34198 < len__24559__auto___34197)){
args__24566__auto__.push((arguments[i__24560__auto___34198]));

var G__34199 = (i__24560__auto___34198 + (1));
i__24560__auto___34198 = G__34199;
continue;
} else {
}
break;
}

var argseq__24567__auto__ = ((((0) < args__24566__auto__.length))?(new cljs.core.IndexedSeq(args__24566__auto__.slice((0)),(0),null)):null);
return octet.spec.indexed_spec.cljs$core$IFn$_invoke$arity$variadic(argseq__24567__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 (seq34196){
return octet.spec.indexed_spec.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq34196));
});

/**
 * 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__24566__auto__ = [];
var len__24559__auto___34206 = arguments.length;
var i__24560__auto___34207 = (0);
while(true){
if((i__24560__auto___34207 < len__24559__auto___34206)){
args__24566__auto__.push((arguments[i__24560__auto___34207]));

var G__34208 = (i__24560__auto___34207 + (1));
i__24560__auto___34207 = G__34208;
continue;
} else {
}
break;
}

var argseq__24567__auto__ = ((((0) < args__24566__auto__.length))?(new cljs.core.IndexedSeq(args__24566__auto__.slice((0)),(0),null)):null);
return octet.spec.spec.cljs$core$IFn$_invoke$arity$variadic(argseq__24567__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__34200_SHARP_){
if(!((p1__34200_SHARP_ == null))){
if((false) || ((cljs.core.PROTOCOL_SENTINEL === p1__34200_SHARP_.octet$spec$ISpec$))){
return true;
} else {
if((!p1__34200_SHARP_.cljs$lang$protocol_mask$partition$)){
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,p1__34200_SHARP_);
} else {
return false;
}
}
} else {
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,p1__34200_SHARP_);
}
});})(numparams))
,params)){
return cljs.core.apply.call(null,octet.spec.indexed_spec,params);
} else {
if((function (){var and__23326__auto__ = cljs.core.even_QMARK_.call(null,numparams);
if(and__23326__auto__){
var and__23326__auto____$1 = (cljs.core.first.call(null,params) instanceof cljs.core.Keyword);
if(and__23326__auto____$1){
var G__34205 = cljs.core.second.call(null,params);
if(!((G__34205 == null))){
if((false) || ((cljs.core.PROTOCOL_SENTINEL === G__34205.octet$spec$ISpec$))){
return true;
} else {
if((!G__34205.cljs$lang$protocol_mask$partition$)){
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,G__34205);
} else {
return false;
}
}
} else {
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,G__34205);
}
} else {
return and__23326__auto____$1;
}
} else {
return and__23326__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 (seq34201){
return octet.spec.spec.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq34201));
});

/**
 * 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$spec34220 !== '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$spec34220 = (function (n,type,meta34221){
this.n = n;
this.type = type;
this.meta34221 = meta34221;
this.cljs$lang$protocol_mask$partition0$ = 393216;
this.cljs$lang$protocol_mask$partition1$ = 0;
})
octet.spec.t_octet$spec34220.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (_34222,meta34221__$1){
var self__ = this;
var _34222__$1 = this;
return (new octet.spec.t_octet$spec34220(self__.n,self__.type,meta34221__$1));
});

octet.spec.t_octet$spec34220.prototype.cljs$core$IMeta$_meta$arity$1 = (function (_34222){
var self__ = this;
var _34222__$1 = this;
return self__.meta34221;
});

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

octet.spec.t_octet$spec34220.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$spec34220.prototype.octet$spec$ISpecDynamicSize$ = cljs.core.PROTOCOL_SENTINEL;

octet.spec.t_octet$spec34220.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__34223){
var vec__34224 = p__34223;
var index = cljs.core.nth.call(null,vec__34224,(0),null);
var data__$1 = cljs.core.nth.call(null,vec__34224,(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$spec34220.prototype.octet$spec$ISpec$ = cljs.core.PROTOCOL_SENTINEL;

octet.spec.t_octet$spec34220.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__34228 = octet.spec.read.call(null,type__$1,buff,index);
var readedbytes = cljs.core.nth.call(null,vec__34228,(0),null);
var readeddata = cljs.core.nth.call(null,vec__34228,(1),null);
var G__34231 = (index + readedbytes);
var G__34232 = cljs.core.conj.call(null,result,readeddata);
var G__34233 = cljs.core.rest.call(null,types);
index = G__34231;
result = G__34232;
types = G__34233;
continue;
} else {
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [(index - pos),result], null);
}
break;
}
});

octet.spec.t_octet$spec34220.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__34234 = cljs.core.rest.call(null,data__$1);
var G__34235 = (written + written_SINGLEQUOTE_);
data__$1 = G__34234;
written = G__34235;
continue;
} else {
return (written - pos);
}
break;
}
});

octet.spec.t_octet$spec34220.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,"meta34221","meta34221",-366273044,null)], null);
});

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

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

octet.spec.t_octet$spec34220.cljs$lang$ctorPrWriter = (function (this__23995__auto__,writer__23996__auto__,opt__23997__auto__){
return cljs.core._write.call(null,writer__23996__auto__,"octet.spec/t_octet$spec34220");
});

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

}

return (new octet.spec.t_octet$spec34220(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$spec34242 !== 'undefined'){
} else {

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

octet.spec.t_octet$spec34242.prototype.cljs$core$IMeta$_meta$arity$1 = ((function (spec_SINGLEQUOTE_){
return (function (_34244){
var self__ = this;
var _34244__$1 = this;
return self__.meta34243;
});})(spec_SINGLEQUOTE_))
;

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

octet.spec.t_octet$spec34242.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$spec34242.prototype.octet$spec$ISpec$ = cljs.core.PROTOCOL_SENTINEL;

octet.spec.t_octet$spec34242.prototype.octet$spec$ISpec$read$arity$3 = ((function (spec_SINGLEQUOTE_){
return (function (_,buff,pos){
var self__ = this;
var ___$1 = this;
var vec__34245 = octet.spec.read.call(null,self__.spec_SINGLEQUOTE_,buff,pos);
var readed = cljs.core.nth.call(null,vec__34245,(0),null);
var data = cljs.core.nth.call(null,vec__34245,(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$spec34242.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$spec34242.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,"meta34243","meta34243",1554277222,null)], null);
});})(spec_SINGLEQUOTE_))
;

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

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

octet.spec.t_octet$spec34242.cljs$lang$ctorPrWriter = ((function (spec_SINGLEQUOTE_){
return (function (this__23995__auto__,writer__23996__auto__,opt__23997__auto__){
return cljs.core._write.call(null,writer__23996__auto__,"octet.spec/t_octet$spec34242");
});})(spec_SINGLEQUOTE_))
;

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

}

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