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

/**
 * 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__4433__auto__ = (((_ == null))?null:_);
var m__4434__auto__ = (octet.spec.read[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,_,buff,start);
} else {
var m__4431__auto__ = (octet.spec.read["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.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__4433__auto__ = (((_ == null))?null:_);
var m__4434__auto__ = (octet.spec.write[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,_,buff,start,data);
} else {
var m__4431__auto__ = (octet.spec.write["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.call(null,_,buff,start,data);
} else {
throw cljs.core.missing_protocol.call(null,"ISpec.write",_);
}
}
}
});


/**
 * Abstraction to support specs having references to other
 * specs within an AssociativeSpec or an IndexedSpec
 * @interface
 */
octet.spec.ISpecWithRef = function(){};

/**
 * Read data from buffer, use data to calculate length etc
 */
octet.spec.read_STAR_ = (function octet$spec$read_STAR_(_,buff,start,data){
if((((!((_ == null)))) && ((!((_.octet$spec$ISpecWithRef$read_STAR_$arity$4 == null)))))){
return _.octet$spec$ISpecWithRef$read_STAR_$arity$4(_,buff,start,data);
} else {
var x__4433__auto__ = (((_ == null))?null:_);
var m__4434__auto__ = (octet.spec.read_STAR_[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,_,buff,start,data);
} else {
var m__4431__auto__ = (octet.spec.read_STAR_["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.call(null,_,buff,start,data);
} else {
throw cljs.core.missing_protocol.call(null,"ISpecWithRef.read*",_);
}
}
}
});

/**
 * Write data from buffer, use data to store length etc
 */
octet.spec.write_STAR_ = (function octet$spec$write_STAR_(_,buff,start,value,types,data){
if((((!((_ == null)))) && ((!((_.octet$spec$ISpecWithRef$write_STAR_$arity$6 == null)))))){
return _.octet$spec$ISpecWithRef$write_STAR_$arity$6(_,buff,start,value,types,data);
} else {
var x__4433__auto__ = (((_ == null))?null:_);
var m__4434__auto__ = (octet.spec.write_STAR_[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,_,buff,start,value,types,data);
} else {
var m__4431__auto__ = (octet.spec.write_STAR_["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.call(null,_,buff,start,value,types,data);
} else {
throw cljs.core.missing_protocol.call(null,"ISpecWithRef.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__4433__auto__ = (((_ == null))?null:_);
var m__4434__auto__ = (octet.spec.size[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,_);
} else {
var m__4431__auto__ = (octet.spec.size["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.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__4433__auto__ = (((_ == null))?null:_);
var m__4434__auto__ = (octet.spec.size_STAR_[goog.typeOf(x__4433__auto__)]);
if((!((m__4434__auto__ == null)))){
return m__4434__auto__.call(null,_,data);
} else {
var m__4431__auto__ = (octet.spec.size_STAR_["_"]);
if((!((m__4431__auto__ == null)))){
return m__4431__auto__.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__27373_SHARP_,p2__27374_SHARP_){
return (p1__27373_SHARP_ + octet.spec.size.call(null,p2__27374_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__27375){
var vec__27376 = p__27375;
var field = cljs.core.nth.call(null,vec__27376,(0),null);
var data__$2 = cljs.core.nth.call(null,vec__27376,(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__5718__auto__ = cljs.core.first.call(null,pairs);
if(cljs.core.truth_(temp__5718__auto__)){
var vec__27380 = temp__5718__auto__;
var fieldname = cljs.core.nth.call(null,vec__27380,(0),null);
var type = cljs.core.nth.call(null,vec__27380,(1),null);
var vec__27383 = (((((!((type == null))))?((((false) || ((cljs.core.PROTOCOL_SENTINEL === type.octet$spec$ISpecWithRef$))))?true:(((!type.cljs$lang$protocol_mask$partition$))?cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecWithRef,type):false)):cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecWithRef,type)))?octet.spec.read_STAR_.call(null,type,buff,index,result):octet.spec.read.call(null,type,buff,index));
var readedbytes = cljs.core.nth.call(null,vec__27383,(0),null);
var readeddata = cljs.core.nth.call(null,vec__27383,(1),null);
var G__27392 = (index + readedbytes);
var G__27393 = octet.util.assoc_ordered.call(null,result,fieldname,readeddata);
var G__27394 = cljs.core.rest.call(null,pairs);
index = G__27392;
result = G__27393;
pairs = G__27394;
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__27387){
var vec__27388 = p__27387;
var fieldname = cljs.core.nth.call(null,vec__27388,(0),null);
var type = cljs.core.nth.call(null,vec__27388,(1),null);
var value = cljs.core.get.call(null,data_SINGLEQUOTE_,fieldname,null);
var written = (((((!((type == null))))?((((false) || ((cljs.core.PROTOCOL_SENTINEL === type.octet$spec$ISpecWithRef$))))?true:(((!type.cljs$lang$protocol_mask$partition$))?cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecWithRef,type):false)):cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecWithRef,type)))?octet.spec.write_STAR_.call(null,type,buff,index,value,self__.dict,data_SINGLEQUOTE_):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__4374__auto__,writer__4375__auto__,opt__4376__auto__){
return cljs.core._write.call(null,writer__4375__auto__,"octet.spec/AssociativeSpec");
});

/**
 * Positional factory function for 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__27395_SHARP_,p2__27396_SHARP_){
return (p1__27395_SHARP_ + octet.spec.size.call(null,p2__27396_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__27397){
var vec__27398 = p__27397;
var index = cljs.core.nth.call(null,vec__27398,(0),null);
var data__$1 = cljs.core.nth.call(null,vec__27398,(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__5718__auto__ = cljs.core.first.call(null,types__$1);
if(cljs.core.truth_(temp__5718__auto__)){
var type = temp__5718__auto__;
var vec__27406 = (((((!((type == null))))?((((false) || ((cljs.core.PROTOCOL_SENTINEL === type.octet$spec$ISpecWithRef$))))?true:(((!type.cljs$lang$protocol_mask$partition$))?cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecWithRef,type):false)):cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecWithRef,type)))?octet.spec.read_STAR_.call(null,type,buff,index,result):octet.spec.read.call(null,type,buff,index));
var readedbytes = cljs.core.nth.call(null,vec__27406,(0),null);
var readeddata = cljs.core.nth.call(null,vec__27406,(1),null);
var G__27415 = (index + readedbytes);
var G__27416 = cljs.core.conj.call(null,result,readeddata);
var G__27417 = cljs.core.rest.call(null,types__$1);
index = G__27415;
result = G__27416;
types__$1 = G__27417;
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__27410){
var vec__27411 = p__27410;
var index = cljs.core.nth.call(null,vec__27411,(0),null);
var type = cljs.core.nth.call(null,vec__27411,(1),null);
var value = cljs.core.nth.call(null,data_SINGLEQUOTE_,index,null);
var written = (((((!((type == null))))?((((false) || ((cljs.core.PROTOCOL_SENTINEL === type.octet$spec$ISpecWithRef$))))?true:(((!type.cljs$lang$protocol_mask$partition$))?cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecWithRef,type):false)):cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecWithRef,type)))?octet.spec.write_STAR_.call(null,type,buff,pos__$1,value,self__.types,data_SINGLEQUOTE_):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__4374__auto__,writer__4375__auto__,opt__4376__auto__){
return cljs.core._write.call(null,writer__4375__auto__,"octet.spec/IndexedSpec");
});

/**
 * Positional factory function for octet.spec/IndexedSpec.
 */
octet.spec.__GT_IndexedSpec = (function octet$spec$__GT_IndexedSpec(types){
return (new octet.spec.IndexedSpec(types));
});

octet.spec.spec_QMARK_ = (function octet$spec$spec_QMARK_(s){
var or__4131__auto__ = (((!((s == null))))?((((false) || ((cljs.core.PROTOCOL_SENTINEL === s.octet$spec$ISpecWithRef$))))?true:(((!s.cljs$lang$protocol_mask$partition$))?cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecWithRef,s):false)):cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpecWithRef,s));
if(or__4131__auto__){
return or__4131__auto__;
} else {
if((!((s == null)))){
if(((false) || ((cljs.core.PROTOCOL_SENTINEL === s.octet$spec$ISpec$)))){
return true;
} else {
if((!s.cljs$lang$protocol_mask$partition$)){
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,s);
} else {
return false;
}
}
} else {
return cljs.core.native_satisfies_QMARK_.call(null,octet.spec.ISpec,s);
}
}
});
octet.spec.associative_spec = (function octet$spec$associative_spec(var_args){
var args__4736__auto__ = [];
var len__4730__auto___27422 = arguments.length;
var i__4731__auto___27423 = (0);
while(true){
if((i__4731__auto___27423 < len__4730__auto___27422)){
args__4736__auto__.push((arguments[i__4731__auto___27423]));

var G__27424 = (i__4731__auto___27423 + (1));
i__4731__auto___27423 = G__27424;
continue;
} else {
}
break;
}

var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null);
return octet.spec.associative_spec.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__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.apply.call(null,cljs.core.array_map,params);
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);

/** @this {Function} */
octet.spec.associative_spec.cljs$lang$applyTo = (function (seq27421){
var self__4718__auto__ = this;
return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq27421));
});

octet.spec.indexed_spec = (function octet$spec$indexed_spec(var_args){
var args__4736__auto__ = [];
var len__4730__auto___27426 = arguments.length;
var i__4731__auto___27427 = (0);
while(true){
if((i__4731__auto___27427 < len__4730__auto___27426)){
args__4736__auto__.push((arguments[i__4731__auto___27427]));

var G__27428 = (i__4731__auto___27427 + (1));
i__4731__auto___27427 = G__27428;
continue;
} else {
}
break;
}

var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null);
return octet.spec.indexed_spec.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__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);

/** @this {Function} */
octet.spec.indexed_spec.cljs$lang$applyTo = (function (seq27425){
var self__4718__auto__ = this;
return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq27425));
});

/**
 * 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__4736__auto__ = [];
var len__4730__auto___27430 = arguments.length;
var i__4731__auto___27431 = (0);
while(true){
if((i__4731__auto___27431 < len__4730__auto___27430)){
args__4736__auto__.push((arguments[i__4731__auto___27431]));

var G__27432 = (i__4731__auto___27431 + (1));
i__4731__auto___27431 = G__27432;
continue;
} else {
}
break;
}

var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null);
return octet.spec.spec.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__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,octet.spec.spec_QMARK_,params)){
return cljs.core.apply.call(null,octet.spec.indexed_spec,params);
} else {
if(((cljs.core.even_QMARK_.call(null,numparams)) && ((cljs.core.first.call(null,params) instanceof cljs.core.Keyword)) && (octet.spec.spec_QMARK_.call(null,cljs.core.second.call(null,params))))){
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);

/** @this {Function} */
octet.spec.spec.cljs$lang$applyTo = (function (seq27429){
var self__4718__auto__ = this;
return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq.call(null,seq27429));
});

/**
 * 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 !== 'undefined') && (typeof octet.spec !== 'undefined') && (typeof octet.spec.t_octet$spec27433 !== '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$spec27433 = (function (n,type,meta27434){
this.n = n;
this.type = type;
this.meta27434 = meta27434;
this.cljs$lang$protocol_mask$partition0$ = 393216;
this.cljs$lang$protocol_mask$partition1$ = 0;
});
octet.spec.t_octet$spec27433.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (_27435,meta27434__$1){
var self__ = this;
var _27435__$1 = this;
return (new octet.spec.t_octet$spec27433(self__.n,self__.type,meta27434__$1));
});

octet.spec.t_octet$spec27433.prototype.cljs$core$IMeta$_meta$arity$1 = (function (_27435){
var self__ = this;
var _27435__$1 = this;
return self__.meta27434;
});

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

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

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

octet.spec.t_octet$spec27433.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__5718__auto__ = cljs.core.first.call(null,types);
if(cljs.core.truth_(temp__5718__auto__)){
var type__$1 = temp__5718__auto__;
var vec__27444 = octet.spec.read.call(null,type__$1,buff,index);
var readedbytes = cljs.core.nth.call(null,vec__27444,(0),null);
var readeddata = cljs.core.nth.call(null,vec__27444,(1),null);
var G__27447 = (index + readedbytes);
var G__27448 = cljs.core.conj.call(null,result,readeddata);
var G__27449 = cljs.core.rest.call(null,types);
index = G__27447;
result = G__27448;
types = G__27449;
continue;
} else {
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [(index - pos),result], null);
}
break;
}
});

octet.spec.t_octet$spec27433.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__5718__auto__ = cljs.core.first.call(null,data__$1);
if(cljs.core.truth_(temp__5718__auto__)){
var value = temp__5718__auto__;
var written_SINGLEQUOTE_ = octet.spec.write.call(null,self__.type,buff,written,value);
var G__27450 = cljs.core.rest.call(null,data__$1);
var G__27451 = (written + written_SINGLEQUOTE_);
data__$1 = G__27450;
written = G__27451;
continue;
} else {
return (written - pos);
}
break;
}
});

octet.spec.t_octet$spec27433.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,"meta27434","meta27434",352217674,null)], null);
});

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

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

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

/**
 * Positional factory function for octet.spec/t_octet$spec27433.
 */
octet.spec.__GT_t_octet$spec27433 = (function octet$spec$repeat_$___GT_t_octet$spec27433(n__$1,type__$1,meta27434){
return (new octet.spec.t_octet$spec27433(n__$1,type__$1,meta27434));
});

}

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

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

octet.spec.t_octet$spec27452.prototype.cljs$core$IMeta$_meta$arity$1 = ((function (spec_SINGLEQUOTE_){
return (function (_27454){
var self__ = this;
var _27454__$1 = this;
return self__.meta27453;
});})(spec_SINGLEQUOTE_))
;

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

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

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

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

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

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

/**
 * Positional factory function for octet.spec/t_octet$spec27452.
 */
octet.spec.__GT_t_octet$spec27452 = ((function (spec_SINGLEQUOTE_){
return (function octet$spec$compose_$___GT_t_octet$spec27452(constructor$__$1,types__$1,spec_SINGLEQUOTE___$1,meta27453){
return (new octet.spec.t_octet$spec27452(constructor$__$1,types__$1,spec_SINGLEQUOTE___$1,meta27453));
});})(spec_SINGLEQUOTE_))
;

}

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