public override object Read(uint type, NativeBufferStream buffer, int offset, int cnt) { Google.Protobuf.MessageParser parser; DataParsers.TryGetValue(type, out parser); if (parser != null) { try { buffer.Seek(offset, SeekOrigin.Begin); buffer.SetLength(offset + cnt); var rv = parser.ParseFrom(buffer); return(rv); } catch (Exception e) { PlatDependant.LogError(e); } } return(null); }
public void Write(NativeBufferStream buffer, int offset, int count) { if (_Con != null) { buffer.Seek(0, SeekOrigin.Begin); int cntwrote = 0; while (cntwrote < count) { var sbuffer = BufferPool.GetBufferFromPool(); int scnt = count - cntwrote; if (sbuffer.Length < scnt) { scnt = sbuffer.Length; } buffer.Read(sbuffer, 0, scnt); _Con.Send(sbuffer, scnt); cntwrote += scnt; } } }
public override void PrepareBlock(NativeBufferStream data, uint type, uint flags, uint seq, uint sseq) { if (data != null) { var size = data.Count; var codedstream = GetCodedOutputStream(); codedstream.Reinit(data); data.InsertMode = true; data.Seek(0, SeekOrigin.Begin); codedstream.WriteTag(1, Google.Protobuf.WireFormat.WireType.Varint); codedstream.WriteUInt32(type); codedstream.WriteTag(2, Google.Protobuf.WireFormat.WireType.Varint); codedstream.WriteUInt32(flags); codedstream.WriteTag(3, Google.Protobuf.WireFormat.WireType.Varint); codedstream.WriteUInt32(seq); codedstream.WriteTag(4, Google.Protobuf.WireFormat.WireType.Varint); codedstream.WriteUInt32(sseq); codedstream.WriteTag(5, Google.Protobuf.WireFormat.WireType.LengthDelimited); codedstream.WriteLength(size); codedstream.Flush(); ReturnCodedOutputStream(codedstream); } }