-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from dbohdan/master
Extension types, timestamp, UTF-8 fix
- Loading branch information
Showing
23 changed files
with
1,411 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ packerObject pack args | |
packerObject reset | ||
msgpack::unpacker new | ||
unpackerObject destroy | ||
unpackerObject set_ext_unpacker ?type? ?script? | ||
unpackerObject unpack_stream istream callback | ||
unpackerObject unpack_string istring ?callback? | ||
msgpack array2list | ||
|
@@ -32,7 +33,7 @@ msgpack unpack string | |
DESCRIPTION | ||
=========== | ||
|
||
The _msgpack_ package is a pure Tcl implementation the MessagePack object | ||
The _msgpack_ package is a pure Tcl implementation of the MessagePack object | ||
serialization library. You can find the code at GitHub: | ||
<URL:https://github.com/jdc8/msgpack>. MessagePack can be found at | ||
<URL:http://msgpack.org/>. | ||
|
@@ -78,6 +79,13 @@ Unpacker class | |
|
||
Destroy the unpacker object. | ||
|
||
unpackerObject set_ext_unpacker ?type? ?script? | ||
|
||
Set the handler for an extension type. When the unpacker encounters | ||
extension type type, it will call script with the type and the data as | ||
its arguments. Omit script or script and type to get handlers. Set the | ||
handler for a type to an empty string to disable it. | ||
|
||
unpackerObject unpack_stream istream callback | ||
|
||
Unpack data read from the istream argument. The callback command is | ||
|
@@ -111,23 +119,27 @@ Unpacker class | |
Type information found in the unpacked MessagePack objects can be one of the | ||
following: | ||
|
||
nil | ||
array | ||
|
||
bin | ||
|
||
boolean | ||
|
||
integer | ||
ext | ||
|
||
float32 | ||
|
||
float64 | ||
|
||
bin | ||
integer | ||
|
||
str | ||
map | ||
|
||
array | ||
nil | ||
|
||
map | ||
str | ||
|
||
timestamp | ||
|
||
Values can be nested type/value list. | ||
|
||
|
@@ -186,10 +198,34 @@ specifiers and if needed a value. The list below shows the supported types: | |
map with the dict size as argument, followed by calling method pack | ||
keyType and method pack valueType for each key/value pair in the dict. | ||
|
||
ext type bytes | ||
|
||
Add a byte array of a chosen extension type to the packed data. | ||
|
||
false | ||
|
||
Add a boolean with value false to the packed data. | ||
|
||
fix_ext1 type byte | ||
|
||
Add 1 byte of a chosen extension type to the packed data. | ||
|
||
fix_ext2 type bytes | ||
|
||
Add 2 bytes of a chosen extension type to the packed data. | ||
|
||
fix_ext4 type bytes | ||
|
||
Add 4 bytes of a chosen extension type to the packed data. | ||
|
||
fix_ext8 type bytes | ||
|
||
Add 8 bytes of a chosen extension type to the packed data. | ||
|
||
fix_ext16 type bytes | ||
|
||
Add 16 bytes of a chosen extension type to the packed data. | ||
|
||
fix_int8 data | ||
|
||
Add an 8 bit integer to the packed data. | ||
|
@@ -224,7 +260,7 @@ specifiers and if needed a value. The list below shows the supported types: | |
|
||
float32 data | ||
|
||
add a 32-bit float to the packed data. | ||
Add a 32-bit float to the packed data. | ||
|
||
float64 data | ||
|
||
|
@@ -274,6 +310,14 @@ specifiers and if needed a value. The list below shows the supported types: | |
Add the map size to the packed data. Must be followed by size pairs of | ||
calls to method pack to add the keys and values to the packed data. | ||
|
||
microseconds micros | ||
|
||
Add a microsecond timestamp to the packed data as a timestamp96. | ||
|
||
milliseconds millis | ||
|
||
Add a millisecond timestamp to the packed data as a timestamp96. | ||
|
||
nil | ||
|
||
Add a nil to the packed data. | ||
|
@@ -293,6 +337,22 @@ specifiers and if needed a value. The list below shows the supported types: | |
pack keyType and method pack valueType for each key/value pair in the | ||
array. | ||
|
||
timestamp32 seconds | ||
|
||
Add a 32-bit unsigned timestamp to the packed data. | ||
|
||
timestamp64 seconds nanoseconds | ||
|
||
Add a 64-bit timestamp (34 bits for seconds, 30 bits for nanoseconds, | ||
both unsigned) to the packed data. Nanoseconds must not exceed | ||
999999999. | ||
|
||
timestamp96 seconds nanoseconds | ||
|
||
Add a 96-bit timestamp (64 bits for seconds, signed, and 32 bits for | ||
nanoseconds, unsigned) to the packed data. Nanoseconds must not exceed | ||
999999999. | ||
|
||
true | ||
|
||
Add a boolean with value true to the packed data. | ||
|
@@ -378,6 +438,26 @@ unpack utility function: | |
|
||
| {integer 4294967295} {bin {A Utility example}} {map {{integer 3} {str three} {integer 4} {str four}}} | ||
|
||
With set_ext_unpacker you can register a handler to unpack custom extension | ||
types. | ||
|
||
| set up [msgpack::unpacker new] | ||
|
||
| proc xor {n type data} { | ||
| set res {} | ||
| foreach b [split $data {}] { | ||
| set code [scan $b %c] | ||
| append res [format %c [expr { $code ^ $n }]] | ||
| } | ||
|
||
| return [list encrypted $res] | ||
| } | ||
|
||
| $up set_ext_unpacker 100 {xor 5} | ||
| # Prints "{encrypted Hello!}". | ||
| puts [$up unpack_string [msgpack pack ext 100 M`iij$]] | ||
| $up destroy | ||
|
||
Bugs, ideas, feedback | ||
===================== | ||
|
||
|
@@ -405,5 +485,6 @@ Serialization | |
COPYRIGHT | ||
========= | ||
|
||
Copyright (c) Jos Decoster <[email protected]> | ||
Copyright (c) 2013 Jos Decoster <[email protected]> | ||
Copyright (c) 2020 D. Bohdan <https://dbohdan.com/> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[comment {-*- tcl -*- doctools manpage}] | ||
[manpage_begin msgpack n 2.0.0] | ||
[copyright {Jos Decoster <[email protected]>}] | ||
[copyright {2013 Jos Decoster <[email protected]>}] | ||
[copyright {2020 D. Bohdan <https://dbohdan.com/>}] | ||
[moddesc {A pure Tcl implementation of the MessagePack object serialization library}] | ||
[category {Serialization}] | ||
[keywords {MessagePack}] | ||
|
@@ -11,8 +12,8 @@ | |
[require msgpack [opt 2.0.0]] | ||
[description] | ||
|
||
The [term msgpack] package is a pure Tcl implementation the MessagePack object | ||
serialization library. You can find the code at GitHub: | ||
The [term msgpack] package is a pure Tcl implementation of the MessagePack | ||
object serialization library. You can find the code at GitHub: | ||
[uri https://github.com/jdc8/msgpack]. MessagePack can be found at | ||
[uri http://msgpack.org/]. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.