// 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__34142_SHARP_,p2__34143_SHARP_){
return (p1__34142_SHARP_ + octet.spec.size.call(null,p2__34143_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__34144){
var vec__34145 = p__34144;
var field = cljs.core.nth.call(null,vec__34145,(0),null);
var data__$2 = cljs.core.nth.call(null,vec__34145,(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__34149 = temp__5276__auto__;
var fieldname = cljs.core.nth.call(null,vec__34149,(0),null);
var type = cljs.core.nth.call(null,vec__34149,(1),null);
var vec__34152 = octet.spec.read.call(null,type,buff,index);
var readedbytes = cljs.core.nth.call(null,vec__34152,(0),null);
var readeddata = cljs.core.nth.call(null,vec__34152,(1),null);
var G__34159 = (index + readedbytes);
var G__34160 = cljs.core.assoc.call(null,result,fieldname,readeddata);
var G__34161 = cljs.core.rest.call(null,pairs);
index = G__34159;
result = G__34160;
pairs = G__34161;
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__34155){
var vec__34156 = p__34155;
var fieldname = cljs.core.nth.call(null,vec__34156,(0),null);
var type = cljs.core.nth.call(null,vec__34156,(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__34162_SHARP_,p2__34163_SHARP_){
return (p1__34162_SHARP_ + octet.spec.size.call(null,p2__34163_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__34164){
var vec__34165 = p__34164;
var index = cljs.core.nth.call(null,vec__34165,(0),null);
var data__$1 = cljs.core.nth.call(null,vec__34165,(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__34169 = octet.spec.read.call(null,type,buff,index);
var readedbytes = cljs.core.nth.call(null,vec__34169,(0),null);
var readeddata = cljs.core.nth.call(null,vec__34169,(1),null);
var G__34176 = (index + readedbytes);
var G__34177 = cljs.core.conj.call(null,result,readeddata);
var G__34178 = cljs.core.rest.call(null,types__$1);
index = G__34176;
result = G__34177;
types__$1 = G__34178;
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__34172){
var vec__34173 = p__34172;
var index = cljs.core.nth.call(null,vec__34173,(0),null);
var type = cljs.core.nth.call(null,vec__34173,(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___34180 = arguments.length;
var i__24560__auto___34181 = (0);
while(true){
if((i__24560__auto___34181 < len__24559__auto___34180)){
args__24566__auto__.push((arguments[i__24560__auto___34181]));

var G__34182 = (i__24560__auto___34181 + (1));
i__24560__auto___34181 = G__34182;
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 (seq34179){
return octet.spec.associative_spec.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq34179));
});

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

var G__34186 = (i__24560__auto___34185 + (1));
i__24560__auto___34185 = G__34186;
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 (seq34183){
return octet.spec.indexed_spec.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq34183));
});

/**
 * 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___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.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__34187_SHARP_){
if(!((p1__34187_SHARP_ == null))){
if((false) || ((cljs.core.PROTOCOL_SENTINEL === p1__34187_SHARP_.octet$spec$ISpec$))){
return true;
} else {
if((!p1__34187_SHARP_.cljs$lang$protocol_mask$partition$)){
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,p1__34187_SHARP_);
} else {
return false;
}
}
} else {
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,p1__34187_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__34192 = cljs.core.second.call(null,params);
if(!((G__34192 == null))){
if((false) || ((cljs.core.PROTOCOL_SENTINEL === G__34192.octet$spec$ISpec$))){
return true;
} else {
if((!G__34192.cljs$lang$protocol_mask$partition$)){
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,G__34192);
} else {
return false;
}
}
} else {
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,G__34192);
}
} 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 (seq34188){
return octet.spec.spec.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq34188));
});

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

octet.spec.t_octet$spec34207.prototype.cljs$core$IMeta$_meta$arity$1 = (function (_34209){
var self__ = this;
var _34209__$1 = this;
return self__.meta34208;
});

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

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

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

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

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

octet.spec.t_octet$spec34207.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,"meta34208","meta34208",1925667509,null)], null);
});

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

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

octet.spec.t_octet$spec34207.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$spec34207");
});

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

}

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

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

octet.spec.t_octet$spec34229.prototype.cljs$core$IMeta$_meta$arity$1 = ((function (spec_SINGLEQUOTE_){
return (function (_34231){
var self__ = this;
var _34231__$1 = this;
return self__.meta34230;
});})(spec_SINGLEQUOTE_))
;

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

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

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

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

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

octet.spec.t_octet$spec34229.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$spec34229");
});})(spec_SINGLEQUOTE_))
;

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

}

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