Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make it compatible with the latest Nim #32

Merged
merged 1 commit into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions msgpack2any.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ type
of msgNull: nil

proc newMsgAny*(kind: AnyType): MsgAny =
new(result)
result.kind = kind
result = MsgAny(kind: kind)

proc hash*(n: OrderedTable[MsgAny, MsgAny]): Hash {.noSideEffect.}

Expand Down
6 changes: 2 additions & 4 deletions msgpack2json.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ proc toJsonNode*[ByteStream](s: ByteStream): JsonNode =
discard s.readChar()
of 0x80..0x8f, 0xde..0xdf:
let len = s.unpack_map()
new(result)
result.kind = JObject
result = JsonNode(kind: JObject)
result.fields = initOrderedTable[string, JsonNode](nextPowerOfTwo(len))
for i in 0..<len:
let key = toJsonNode(s)
if key.kind != JString: raise conversionError("json key needs a string")
result.fields.add(key.getStr(), toJsonNode(s))
of 0x90..0x9f, 0xdc..0xdd:
let len = s.unpack_array()
new(result)
result.kind = JArray
result = JsonNode(kind: JArray)
result.elems = newSeq[JsonNode](len)
for i in 0..<len:
result.elems[i] = toJsonNode(s)
Expand Down
8 changes: 4 additions & 4 deletions msgpack4nim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ proc pack_imp_int8*[ByteStream](s: ByteStream, val: int8) =
if val < -(1 shl 5):
#signed 8
s.write(chr(0xd0))
s.write(take8_8(uint8(val)))
s.write(take8_8(cast[uint8](val)))
else:
#fixnum
s.write(take8_8(uint8(val)))
s.write(take8_8(cast[uint8](val)))

proc unpack_imp_int8*[ByteStream](s: ByteStream): int8 =
let c = s.readChar
Expand All @@ -333,7 +333,7 @@ proc pack_imp_int16*[ByteStream](s: ByteStream, val: int16) =
if val < -(1 shl 7):
#signed 16
s.write(chr(0xd1))
s.store16(uint16(val))
s.store16(cast[uint16](val))
else:
#signed 8
s.write(chr(0xd0))
Expand Down Expand Up @@ -374,7 +374,7 @@ proc pack_imp_int32*[ByteStream](s: ByteStream, val: int32) =
if val < -(1 shl 15):
#signed 32
s.write(chr(0xd2))
s.store32(uint32(val))
s.store32(cast[uint32](val))
elif val < -(1 shl 7):
#signed 16
s.write(chr(0xd1))
Expand Down