From c7e980ea31a8c1d522998e46d5d51929e1fb21d8 Mon Sep 17 00:00:00 2001 From: cipharius Date: Tue, 9 Nov 2021 04:25:43 +0200 Subject: [PATCH] Updates README with utf8Encode and utf8Decode documentation --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 4760c67..3507f2a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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.