Module msgpack


Ext* = tuple[typ: int, data: seq[byte]]
MsgKind* = enum 
  mkFixArray, mkArray16, mkArray32, mkFixMap, mkMap16, mkMap32, mkNil, mkTrue, 
  mkFalse, mkPFixNum, mkNFixNum, mkUInt8, mkUInt16, mkUInt32, mkUInt64, mkInt8, 
  mkInt16, mkInt32, mkInt64, mkFloat32, mkFloat64, mkFixStr, mkStr8, mkStr16, 
  mkStr32, mkBin8, mkBin16, mkBin32, mkFixExt1, mkFixExt2, mkFixExt4, mkFixExt8, 
  mkFixExt16, mkExt8, mkExt16, mkExt32
Msg* = ref MsgObj
MsgObj* {.acyclic.} = object 
  case kind*: MsgKind
  of mkFixArray: vFixArray*: seq[Msg]
  of mkArray16: vArray16*: seq[Msg]
  of mkArray32: vArray32*: seq[Msg]
  of mkFixMap: vFixMap*: seq[tuple[key: Msg, val: Msg]]
  of mkMap16: vMap16*: seq[tuple[key: Msg, val: Msg]]
  of mkMap32: vMap32*: seq[tuple[key: Msg, val: Msg]]
  of mkNil: nil
  of mkTrue: nil
  of mkFalse: nil
  of mkPFixNum: vPFixNum*: uint8
  of mkNFixNum: vNFixNum*: int8
  of mkUInt8: vUInt8*: uint8
  of mkUInt16: vUInt16*: uint16
  of mkUInt32: vUInt32*: uint32
  of mkUInt64: vUInt64*: uint64
  of mkInt8: vInt8*: int8
  of mkInt16: vInt16*: int16
  of mkInt32: vInt32*: int32
  of mkInt64: vInt64*: int64
  of mkFloat32: vFloat32*: float32
  of mkFloat64: vFloat64*: float64
  of mkFixStr: vFixStr*: string
  of mkStr8: vStr8*: string
  of mkStr16: vStr16*: string
  of mkStr32: vStr32*: string
  of mkBin8: vBin8*: seq[byte]
  of mkBin16: vBin16*: seq[byte]
  of mkBin32: vBin32*: seq[byte]
  of mkFixExt1: vFixExt1: Ext
  of mkFixExt2: vFixExt2: Ext
  of mkFixExt4: vFixExt4: Ext
  of mkFixExt8: vFixExt8: Ext
  of mkFixExt16: vFixExt16: Ext
  of mkExt8: vExt8: Ext
  of mkExt16: vExt16: Ext
  of mkExt32: vExt32: Ext


Nil* = Msg(kind: mkNil)
True* = Msg(kind: mkTrue)
False* = Msg(kind: mkFalse)


proc `$`*(msg: Msg): string
proc FixArray*(v: seq[Msg]): Msg
proc Array16*(v: seq[Msg]): Msg
proc Array32*(v: seq[Msg]): Msg
proc FixMap*(v: seq[tuple[key: Msg, val: Msg]]): Msg
proc Map16*(v: seq[tuple[key: Msg, val: Msg]]): Msg
proc Map32*(v: seq[tuple[key: Msg, val: Msg]]): Msg
proc PFixNum*(v: uint8): Msg
proc NFixNum*(v: int8): Msg
proc UInt8*(v: uint8): Msg
proc UInt16*(v: uint16): Msg
proc UInt32*(v: uint32): Msg
proc UInt64*(v: uint64): Msg
proc Int8*(v: int8): Msg
proc Int16*(v: int16): Msg
proc Int32*(v: int32): Msg
proc Int64*(v: int64): Msg
proc Float32*(v: float32): Msg
proc Float64*(v: float64): Msg
proc FixStr*(v: string): Msg
proc Str8*(s: string): Msg
proc Str16*(s: string): Msg
proc Str32*(s: string): Msg
proc Bin8*(v: seq[byte]): Msg
proc Bin16*(v: seq[byte]): Msg
proc Bin32*(v: seq[byte]): Msg
proc FixExt1*(v: Ext): Msg
proc FixExt2*(v: Ext): Msg
proc FixExt4*(v: Ext): Msg
proc FixExt8*(v: Ext): Msg
proc FixExt16*(v: Ext): Msg
proc Ext8*(v: Ext): Msg
proc Ext16*(v: Ext): Msg
proc Ext32*(v: Ext): Msg
proc wrap*(x: Msg): Msg
proc wrap*(x: bool): Msg
proc wrap*(x: int): Msg
Given x of int and returns a Msg object that is most compression-effective. The rule of thumb is use wrap if you don't know in advance what Msg type it will become, otherwise use specific conversion to Msg which can reduce overhead to determine the Msg type.
proc wrap*(x: float): Msg
proc wrap*(x: string): Msg
proc wrap*(x: seq[byte]): Msg
proc wrap*(x: Ext): Msg
proc wrap*[T: Wrappable](x: seq[T]): Msg
proc wrap*[K: Wrappable, V: Wrappable](x: seq[tuple[key: K, val: V]]): Msg
proc unwrapBool*(x: Msg): bool
proc unwrapInt*(x: Msg): int
proc unwrapFloat*(x: Msg): float
proc unwrapStr*(x: Msg): string
proc unwrapBin*(x: Msg): seq[byte]
proc unwrapArray*(x: Msg): seq[Msg]
proc unwrapMap*(x: Msg): seq[tuple[key: Msg, val: Msg]]
proc unwrapExt*(x: Msg): Ext
proc pack*(st: Stream; msg: Msg)
Serialize message to streaming byte sequence
proc unpack*(st: Stream): Msg
Deserialize streaming byte sequence to message
proc t*(msg: Msg)
Test by cyclic translation. Don't use.


converter toMsg*(x: Msg): Msg
converter toMsg*(x: bool): Msg
converter toMsg*(x: int): Msg
converter toMsg*(x: float): Msg
converter toMsg*(x: string): Msg
converter toMsg*(x: seq[byte]): Msg
converter toMsg*(x: Ext): Msg
converter toMsg*[T: Wrappable](x: seq[T]): Msg
converter toMsg*[K: Wrappable, V: Wrappable](x: seq[tuple[key: K, val: V]]): Msg