Changeset 39759 in project
- Timestamp:
- 03/26/21 19:43:09 (4 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wiki/eggref/5/msgpack
r39755 r39759 1 2 1 == msgpack 3 2 [[toc:]] … … 5 4 6 5 Forked from [[http://github.com/hugoArregui/msgpack-scheme|msgpack-scheme]] and partially rewritten 7 (ported to CHICKEN 5 and cleaned up).8 I kept the original license and most of the original API. However the byte-blob have been replaced with6 (ported to CHICKEN 5 and built-in byte blob API). 7 I kept the original license and most of the original API. However, the byte-blob have been replaced with 9 8 Chicken 5 native blob. 10 9 I removed the dependency on bind egg and the need for C++ code using built-ins features of C5. … … 13 12 === Authors 14 13 Hugo Arregui: Original author of the egg. 14 15 15 Théo Cavignac: ported the egg to Chicken 5 16 16 … … 22 22 === Requirements 23 23 This package requires the following eggs: 24 - matchable 25 - srfi-1 26 - srfi-69 24 25 * matchable 26 * srfi-1 27 * srfi-69 27 28 28 29 … … 32 33 33 34 From source: 34 First install the required eggs listed above. 35 Then clone this [[https://github.com/Lattay/chicken-msgpack|repository]]. 36 Finally run {{chicken-install -s}} in the root of this repository. 35 36 # Install the required eggs listed above. 37 # Clone this [[https://github.com/Lattay/chicken-msgpack|repository]]. 38 # Run {{chicken-install -s}} in the root of this repository. 37 39 38 40 … … 40 42 Primitive pack-family procedures: 41 43 42 <enscript highlight="scheme"> 43 (pack-uint port value) ; will produce an error if the input is negative 44 (pack-sint port value) 45 (pack-float port FLONUM) ; pack 32b floats, support both exact and inexact but convert to flonum (inexact) anyway 46 (pack-double port FLONUM) ; pack 64b floats, same limitations as above 47 (pack-bin port BLOB) ; chicken.blob byte blob 48 (pack-str port STRING) ; string 49 (pack-array port VECTOR) ; scheme vector, also support lists 50 (pack-map port HASH-TABLE) ; srfi-69 hash-table 51 (pack-ext port EXT) ; extension (see below) 52 </enscript> 44 <procedure>(pack-uint port value)</procedure> 45 <procedure>(pack-sint port value)</procedure> 46 pack integer, will produce an error if the input does not respect the expected signedness 53 47 54 Also the simplest way to use is to use the generic procedures: 48 <procedure>(pack-float port FLONUM)</procedure> 49 pack 32b floats, support both exact and inexact but convert to flonum (inexact) anyway 55 50 56 <enscript highlight="scheme"> 57 (pack port value) 58 (pack/blob value) 59 </enscript> 51 <procedure>(pack-double port FLONUM)</procedure> 52 pack 64b floats, support both exact and inexact but convert to flonum (inexact) anyway 53 54 <procedure>(pack-bin port BLOB)</procedure> 55 pack chicken.blob byte blob 56 57 <procedure>(pack-str port STRING)</procedure> 58 pack string 59 60 <procedure>(pack-array port VECTOR)</procedure> 61 pack scheme vectors or lists 62 63 <procedure>(pack-map port HASH-TABLE)</procedure> 64 pack srfi-69 hash-table 65 66 <procedure>(pack-ext port EXT)</procedure> 67 pack extension record (see below) 68 69 Automatic procedures: 70 71 <procedure>(pack port value)</procedure> 72 Will infer the right packer to use and write the msgpack result to port 73 74 <procedure>(pack/blob value)</procedure> 75 Will inter the right packer and return the message as a byte blob 60 76 61 77 These procedures will call primitive type packers, with the following rules: 62 - if the value has a packer, apply it. 63 - if the value is a string, it will be packed as str. 64 - if the value is a blob, it will be packed as bin. 65 - if the value is a char, it will be packed as a uint. 66 - if the value is a list, it will be packed as an array. 67 - if the value is a extension (see below), it will be packed as an ext 78 79 * if the value has a packer, apply it. 80 * if the value is a string, it will be packed as str. 81 * if the value is a blob, it will be packed as bin. 82 * if the value is a char, it will be packed as a uint. 83 * if the value is a list, it will be packed as an array. 84 * if the value is a extension (see below), it will be packed as an ext 68 85 69 86 The {{/blob}} version return a blob of packed data, the others directly write it to the port. 70 87 71 88 Unpack procedures: 72 [lang:scheme] 89 <procedure>(unpack port [mapper])</procedure> 90 Read msgpack data from port and return the unpacked data. 73 91 74 (unpack port [mapper]) 75 (unpack/blob blob [mapper]) 92 <procedure>(unpack/blob blob [mapper])</procedure> 93 Treat the blob as a msgpack data and return the unpacked data. 76 94 77 95 The optional mapper argument is applied to the output before returning. … … 82 100 Extension is a record defined as: 83 101 84 {{ 85 (define-record extension type data) 86 }} 102 <enscript highlight="scheme">(define-record extension type data)</enscript> 87 103 88 104 * type: integer from 0 to 127 89 105 * data: a blob 90 106 91 Example:107 Use-case example: 92 108 93 <enscript highlight="scheme"> 94 (make-extension 10 (string->byte-blob "hi")) 95 </enscript> 109 <enscript highlight="scheme">(make-extension 10 (string->byte-blob "hi"))</enscript> 96 110 97 111 … … 101 115 102 116 === History 103 v1.0.3 Ironing details for publication.104 117 105 v1.0.0 Port to Chicken 5. 118 * v1.0.3 Ironing details for publication. 119 120 * v1.0.0 Port to Chicken 5. 106 121 Breaking changes: 107 122 All blob related APIs have been changed to support Chicken native blob type. 108 123 109 v0.4 Last Chicken 4 version (2016)124 * v0.4 Last Chicken 4 version (2016) 110 125
Note: See TracChangeset
for help on using the changeset viewer.