Title: | A library to serialize or unserialize data in MessagePack format |
---|---|
Description: | This is the library that can serialize or unserialize MessagePack format data. |
Authors: | Mikiya TANIZAWA |
Maintainer: | Mikiya TANIZAWA <[email protected]> |
License: | BSD_2_clause + file LICENSE |
Version: | 1.1 |
Built: | 2024-11-06 05:42:11 UTC |
Source: | https://github.com/cran/msgpackR |
This is the library that can serialize or deserialize MessagePack format data.
Package: | MessagePack for R |
Type: | Package |
Version: | 1.1 |
Date: | 2013-11-21 |
License: | BSD_2_clause + file LICENSE |
Mikiya TANIZAWA [email protected]
pack
,
unpack
,
msgpack.writeResult
,
msgpack.matrix
(data <- c(1,2,3)) #[1] 1 2 3 (d <- pack(data)) #[1] 93 01 02 03 msgpack.writeResult("test.txt", d) unpack("test.txt") # <= unserialize from binary file #[1] 1 2 3 unpack(d) # <= unserialize from binary bits #[1] 1 2 3 # example to serialize {"compact":true}, which appears at http://msgpack.org/. sample <- TRUE names(sample) <- c("compact") sample #compact # TRUE pack(sample) #[1] 81 a7 63 6f 6d 70 61 63 74 c3 # Positive FixNum a <- 100 pack(a) #[1] 64 unpack(pack(a)) #[1] 100 # uint16 a <- 2^10 pack(a) #[1] cd 04 00 unpack(pack(a)) #[1] 1024 # int16 a <- -2^10 pack(a) #[1] d1 fc 00 unpack(pack(a)) #[1] -1024 # double a <- 10.1 pack(a) #[1] cb 40 24 33 33 33 33 33 33 unpack(pack(a)) #[1] 10.1 # FixRaw a <- "sample character" pack(a) #[1] b0 73 61 6d 70 6c 65 20 63 68 61 72 61 63 74 65 72 unpack(pack(a)) #[1] "sample character"
(data <- c(1,2,3)) #[1] 1 2 3 (d <- pack(data)) #[1] 93 01 02 03 msgpack.writeResult("test.txt", d) unpack("test.txt") # <= unserialize from binary file #[1] 1 2 3 unpack(d) # <= unserialize from binary bits #[1] 1 2 3 # example to serialize {"compact":true}, which appears at http://msgpack.org/. sample <- TRUE names(sample) <- c("compact") sample #compact # TRUE pack(sample) #[1] 81 a7 63 6f 6d 70 61 63 74 c3 # Positive FixNum a <- 100 pack(a) #[1] 64 unpack(pack(a)) #[1] 100 # uint16 a <- 2^10 pack(a) #[1] cd 04 00 unpack(pack(a)) #[1] 1024 # int16 a <- -2^10 pack(a) #[1] d1 fc 00 unpack(pack(a)) #[1] -1024 # double a <- 10.1 pack(a) #[1] cb 40 24 33 33 33 33 33 33 unpack(pack(a)) #[1] 10.1 # FixRaw a <- "sample character" pack(a) #[1] b0 73 61 6d 70 6c 65 20 63 68 61 72 61 63 74 65 72 unpack(pack(a)) #[1] "sample character"
Transfer list format to matrix format
msgpack.matrix(data)
msgpack.matrix(data)
data |
a list format data that is made from unpack function |
matrix format data
Mikiya TANIZAWA [email protected]
(mat <- matrix(1:6, 2)) # [,1] [,2] [,3] #[1,] 1 3 5 #[2,] 2 4 6 (m <- pack(mat)) # [1] 92 93 01 03 05 93 02 04 06 unpack(m) #[[1]] #[1] 1 3 5 # #[[2]] #[1] 2 4 6 msgpack.matrix(unpack(m)) # [,1] [,2] [,3] #[1,] 1 3 5 #[2,] 2 4 6 colnames(mat) <- c("A","B","C") mat # A B C #[1,] 1 3 5 #[2,] 2 4 6 (m <- pack(mat)) # <= if data has colname, serialize to "map" #[1] 92 83 a1 41 01 a1 42 03 a1 43 05 83 a1 41 02 a1 42 04 a1 43 06 unpack(m) #[[1]] #A B C #1 3 5 # #[[2]] #A B C #2 4 6 msgpack.matrix(unpack(m)) # A B C #[1,] 1 3 5 #[2,] 2 4 6
(mat <- matrix(1:6, 2)) # [,1] [,2] [,3] #[1,] 1 3 5 #[2,] 2 4 6 (m <- pack(mat)) # [1] 92 93 01 03 05 93 02 04 06 unpack(m) #[[1]] #[1] 1 3 5 # #[[2]] #[1] 2 4 6 msgpack.matrix(unpack(m)) # [,1] [,2] [,3] #[1,] 1 3 5 #[2,] 2 4 6 colnames(mat) <- c("A","B","C") mat # A B C #[1,] 1 3 5 #[2,] 2 4 6 (m <- pack(mat)) # <= if data has colname, serialize to "map" #[1] 92 83 a1 41 01 a1 42 03 a1 43 05 83 a1 41 02 a1 42 04 a1 43 06 unpack(m) #[[1]] #A B C #1 3 5 # #[[2]] #A B C #2 4 6 msgpack.matrix(unpack(m)) # A B C #[1,] 1 3 5 #[2,] 2 4 6
Save serialized data to file.
msgpack.writeResult(filename, result)
msgpack.writeResult(filename, result)
filename |
filename that you want to save as |
result |
serialized data that you want to save |
Mikiya TANIZAWA [email protected]
(data <- c(1,2,3)) #[1] 1 2 3 (d <- pack(data)) #[1] 93 01 02 03 msgpack.writeResult("test.txt", d)
(data <- c(1,2,3)) #[1] 1 2 3 (d <- pack(data)) #[1] 93 01 02 03 msgpack.writeResult("test.txt", d)
Serialize data to MessagePack format
pack(data)
pack(data)
data |
data that you want to serialize, e.g. c(1,2,3) |
serialized data to MessagePack format
Mikiya TANIZAWA [email protected]
pack(c(1,2,3)) #[1] 93 01 02 03 mat <- matrix(c(1:6), nrow=2); colnames(mat) <- c("A","B","C"); pack(mat); #[1] 92 83 a1 41 01 a1 42 03 a1 43 05 83 a1 41 02 a1 42 04 a1 43 06
pack(c(1,2,3)) #[1] 93 01 02 03 mat <- matrix(c(1:6), nrow=2); colnames(mat) <- c("A","B","C"); pack(mat); #[1] 92 83 a1 41 01 a1 42 03 a1 43 05 83 a1 41 02 a1 42 04 a1 43 06
Unserialize MessagePack format data
unpack(str)
unpack(str)
str |
str is filename or array of raw data |
unserialized data from MessagePack format
Mikiya TANIZAWA [email protected]
unpack(pack(c(1,2,3))) #[1] 1 2 3 (data <- c(1,2,3)) #[1] 1 2 3 (d <- pack(data)) #[1] 93 01 02 03 msgpack.writeResult("test.txt", d) unpack("test.txt") # <= unserialize from binary file #[1] 1 2 3 unpack(d) # <= unserialize from binary bits #[1] 1 2 3
unpack(pack(c(1,2,3))) #[1] 1 2 3 (data <- c(1,2,3)) #[1] 1 2 3 (d <- pack(data)) #[1] 93 01 02 03 msgpack.writeResult("test.txt", d) unpack("test.txt") # <= unserialize from binary file #[1] 1 2 3 unpack(d) # <= unserialize from binary bits #[1] 1 2 3