示例#1
0
        public static LocalBuffer Alloc(long size)
        {
            LocalBuffer buffer = new LocalBuffer();

            buffer._data.SetLength(size);
            return(buffer);
        }
示例#2
0
        public static LocalBuffer From(string str, Encoding encoding = null)
        {
            LocalBuffer buffer = new LocalBuffer();

            buffer.Write(str, encoding);
            return(buffer);
        }
示例#3
0
        public static Buffer from(LocalBuffer buffer)
        {
            SocketronClient client = SocketronClient.GetCurrent();
            string          script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var buf = Buffer.from({0});",
                    "return {1};"
                    ),
                buffer.Stringify(),
                Script.AddObject("buf")
                );
            int result = client.ExecuteJavaScriptBlocking <int>(script);

            return(new Buffer(client, result));
        }
示例#4
0
        public LocalBuffer Slice(uint offset)
        {
            uint length = (uint)_data.Length - offset;

            byte[] data     = new byte[length];
            long   position = _data.Position;

            _data.Position = offset;
            _data.Read(data, 0, (int)length);
            _data.Position = position;

            LocalBuffer buffer = new LocalBuffer();

            buffer.Write(data);
            return(buffer);
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
0
 public void Write(LocalBuffer buffer)
 {
     byte[] bytes = buffer._data.GetBuffer();
     _data.Write(bytes, 0, bytes.Length);
 }
示例#8
0
 public void Write(LocalBuffer buffer)
 {
     byte[] bytes = buffer.ToByteArray();
     Write(bytes);
 }
示例#9
0
 public Payload()
 {
     Data = new LocalBuffer();
 }