public static LocalBuffer Alloc(long size) { LocalBuffer buffer = new LocalBuffer(); buffer._data.SetLength(size); return(buffer); }
public static LocalBuffer From(string str, Encoding encoding = null) { LocalBuffer buffer = new LocalBuffer(); buffer.Write(str, encoding); return(buffer); }
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)); }
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); }
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); }
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); }
public void Write(LocalBuffer buffer) { byte[] bytes = buffer._data.GetBuffer(); _data.Write(bytes, 0, bytes.Length); }
public void Write(LocalBuffer buffer) { byte[] bytes = buffer.ToByteArray(); Write(bytes); }
public Payload() { Data = new LocalBuffer(); }