コード例 #1
0
        public static LocalBuffer From(JsonObject json)
        {
            if (json == null)
            {
                return(null);
            }
            if (json["type"] as string != "Buffer")
            {
                return(null);
            }
            object[]    data   = json["data"] as object[];
            LocalBuffer buffer = new LocalBuffer();

            foreach (object item in data)
            {
                buffer.WriteUInt8((byte)(int)item);
            }
            return(buffer);
        }
コード例 #2
0
        public LocalBuffer ToBuffer(DataType type, Encoding encoding = null)
        {
            if (encoding == null)
            {
                encoding = Encoding.UTF8;
            }
            string json = Stringify();
            int    size = encoding.GetByteCount(json);

            if (size > ushort.MaxValue)
            {
                return(null);
            }
            LocalBuffer buffer = new LocalBuffer();

            buffer.WriteUInt8((byte)type);
            buffer.WriteUInt16LE((ushort)size);
            buffer.Write(json, encoding);
            return(buffer);
        }