본문으로 바로가기

msgpack

category Tcl & Tk/확장 패키지 (Extension Package) 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

msgpack-master.zip
0.03MB

'Tcl & Tk > 확장 패키지 (Extension Package)' 카테고리의 다른 글

Ttk file selection dialog  (0) 2025.10.13
ticklEcharts 3.2.8  (0) 2025.10.12
TCLFPDF 1.7.2  (0) 2025.10.09
standalone bgexec  (0) 2025.09.30
typed_json  (0) 2025.09.26