티클러
2025. 10. 13. 23:49
홈페이지: https://github.com/jdc8/msgpack
순수 Tcl로 구현된 오브젝트 직렬화 패키지입니다.
# 예제1
package require msgpack
set p [msgpack::packer new]
$p pack int 123456789
$p pack str "A MessagePack example"
$p pack dict int str {1 one 2 two}
set packed_data [$p data]
set u [msgpack::unpacker new]
$u unpack_string $packed_data
# {{integer 123456789} {str {A MessagePack example}} {map {{integer 1} {str one} {integer 2} {str two}}}}
$u destroy
# 예제2
set packed_data ""
append packed_data [msgpack pack int 0xFFFFFFFF]
append packed_data [msgpack pack bin "A Utility example"]
append packed_data [msgpack pack dict int str {3 three 4 four}]}
puts [msgpack unpack $packed_data]
# {{integer 4294967295} {bin {A Utility example}} {map {{integer 3} {str three} {integer 4} {str four}}}}
# 예제3
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