Skip to content

Commit

Permalink
Updates README with utf8Encode and utf8Decode documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cipharius committed Nov 9, 2021
1 parent 53d8904 commit c7e980e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ local message = msgpack.encode({"hello", "world", 123, key="value"})
for i,v in pairs(msgpack.decode(message)) do
print(i, v)
end

-- To store MessagePack message in DataStore, it first needs to be wrapped in UTF8 format
-- This is not nescessary for HttpService or RemoteEvents!
local dataStore = game:GetService("DataStoreService"):GetGlobalDataStore()
dataStore:SetAsync("message", msgpack.utf8Encode(message))

local retrieved = msgpack.utf8Decode(dataStore:GetAsync("message"))
for i,v in pairs(msgpack.decode(retrieved)) do
print(i, v)
end
```

## API
Expand All @@ -38,6 +48,15 @@ end

Decodes MessagePack binary string as pure Luau value.

* `msgpack.utf8Encode(message: string): string`

Wraps binary string in a UTF-8 compatible encoding.
Nescessary to save binary strings (like MessagePack serialized data) in DataStore.

* `msgpack.utf8Decode(blob: string): string`

Unwraps binary string from UTF-8 compatible encoding.

* `msgpack.ByteArray.new(blob: string): msgpack.ByteArray`

Wraps a string value in order to represent MessagePack `bin` datatype.
Expand Down

0 comments on commit c7e980e

Please sign in to comment.