static int WriteTo(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2 && TypeChecker.CheckTypes <Google.ProtocolBuffers.CodedOutputStream>(L, 2)) { MyLib.CGPlayerCmd obj = (MyLib.CGPlayerCmd)ToLua.CheckObject(L, 1, typeof(MyLib.CGPlayerCmd)); Google.ProtocolBuffers.CodedOutputStream arg0 = (Google.ProtocolBuffers.CodedOutputStream)ToLua.ToObject(L, 2); obj.WriteTo(arg0); return(0); } else if (count == 2 && TypeChecker.CheckTypes <System.IO.Stream>(L, 2)) { MyLib.CGPlayerCmd obj = (MyLib.CGPlayerCmd)ToLua.CheckObject(L, 1, typeof(MyLib.CGPlayerCmd)); System.IO.Stream arg0 = (System.IO.Stream)ToLua.ToObject(L, 2); obj.WriteTo(arg0); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: MyLib.CGPlayerCmd.WriteTo")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int WriteTo(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2 && TypeChecker.CheckTypes <Google.ProtocolBuffers.CodedOutputStream>(L, 2)) { Google.ProtocolBuffers.AbstractMessageLite <MyLib.GCPlayerCmd, MyLib.GCPlayerCmd.Builder> obj = (Google.ProtocolBuffers.AbstractMessageLite <MyLib.GCPlayerCmd, MyLib.GCPlayerCmd.Builder>)ToLua.CheckObject <Google.ProtocolBuffers.AbstractMessageLite <MyLib.GCPlayerCmd, MyLib.GCPlayerCmd.Builder> >(L, 1); Google.ProtocolBuffers.CodedOutputStream arg0 = (Google.ProtocolBuffers.CodedOutputStream)ToLua.ToObject(L, 2); obj.WriteTo(arg0); return(0); } else if (count == 2 && TypeChecker.CheckTypes <System.IO.Stream>(L, 2)) { Google.ProtocolBuffers.AbstractMessageLite <MyLib.GCPlayerCmd, MyLib.GCPlayerCmd.Builder> obj = (Google.ProtocolBuffers.AbstractMessageLite <MyLib.GCPlayerCmd, MyLib.GCPlayerCmd.Builder>)ToLua.CheckObject <Google.ProtocolBuffers.AbstractMessageLite <MyLib.GCPlayerCmd, MyLib.GCPlayerCmd.Builder> >(L, 1); System.IO.Stream arg0 = (System.IO.Stream)ToLua.ToObject(L, 2); obj.WriteTo(arg0); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: Google.ProtocolBuffers.AbstractMessageLite<MyLib.GCPlayerCmd,MyLib.GCPlayerCmd.Builder>.WriteTo")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public ServerPacket(byte service, int method, short requestId, ulong listenerId) { m_memStream = new MemoryStream(); m_stream = CodedOutputStream.CreateInstance(m_memStream); // Write header m_stream.WriteRawByte(service); m_stream.WriteInt32NoTag(method); m_stream.WriteInt16NoTag(requestId); Console.WriteLine("OUT: service {0}, method {1}, requestId {2}, listenerId {3}", service, method, requestId, listenerId); if (service != 0xFE) m_stream.WriteRawVarint64(listenerId); }
public void SendMessage(chat.Message msg) { int size = msg.SerializedSize; byte[] buf = new byte[size + 4]; buf[0] = (byte)((size >> 24) & 0x000000ff); buf[1] = (byte)((size >> 16) & 0x000000ff); buf[2] = (byte)((size >> 8) & 0x000000ff); buf[3] = (byte)((size) & 0x000000ff); pb.CodedOutputStream cos = pb.CodedOutputStream.CreateInstance(buf, 4, size); msg.WriteTo(cos); SendMessage(buf); }
/// <summary> /// Serializes the set and writes it to <paramref name="output"/>. /// </summary> public void WriteTo(CodedOutputStream output) { foreach (KeyValuePair<int, UnknownField> entry in fields) { entry.Value.WriteTo(entry.Key, output); } }
/// <summary> /// Serializes the set and writes it to <paramref name="output"/> using /// the MessageSet wire format. /// </summary> public void WriteAsMessageSetTo(CodedOutputStream output) { foreach (KeyValuePair<int, UnknownField> entry in fields) { entry.Value.WriteAsMessageSetExtensionTo(entry.Key, output); } }
/// <summary> /// See <see cref="IMessage.WriteTo(CodedOutputStream)" />. /// </summary> public void WriteTo(CodedOutputStream output) { foreach (KeyValuePair<FieldDescriptor, object> entry in fields) { WriteField(entry.Key, entry.Value, output); } }
/// <summary> /// Writes a single field to a CodedOutputStream. /// </summary> public void WriteField(FieldDescriptor field, Object value, CodedOutputStream output) { if (field.IsExtension && field.ContainingType.Options.MessageSetWireFormat) { output.WriteMessageSetExtension(field.FieldNumber, (IMessage) value); } else { if (field.IsRepeated) { IEnumerable valueList = (IEnumerable) value; if (field.IsPacked) { output.WriteTag(field.FieldNumber, WireFormat.WireType.LengthDelimited); // Compute the total data size so the length can be written. int dataSize = 0; foreach (object element in valueList) { dataSize += CodedOutputStream.ComputeFieldSizeNoTag(field.FieldType, element); } output.WriteRawVarint32((uint)dataSize); // Write the data itself, without any tags. foreach (object element in valueList) { output.WriteFieldNoTag(field.FieldType, element); } } else { foreach (object element in valueList) { output.WriteField(field.FieldType, field.FieldNumber, element); } } } else { output.WriteField(field.FieldType, field.FieldNumber, value); } } }
Stream getStream() { if (rawWriter == null) { rawWriter = baseStream; rawWriter.Write(OrcFile.MAGIC, 0, OrcFile.MAGIC.Length); headerLength = rawWriter.Position; writer = new OutStream("metadata", bufferSize, codec, new DirectStream(rawWriter)); protobufWriter = CodedOutputStream.CreateInstance(writer); } return rawWriter; }
internal CodedBuilder(int size) { buffer = new byte[size]; output = CodedOutputStream.CreateInstance(buffer); }
internal void WriteRawBytesTo(CodedOutputStream outputStream) { outputStream.WriteRawBytes(this.bytes, 0, this.bytes.Length); }
public void TestCodedInputOutputPosition() { byte[] content = new byte[110]; for (int i = 0; i < content.Length; i++) { content[i] = (byte)i; } byte[] child = new byte[120]; { MemoryStream ms = new MemoryStream(child); CodedOutputStream cout = CodedOutputStream.CreateInstance(ms, 20); // Field 11: numeric value: 500 cout.WriteTag(11, WireFormat.WireType.Varint); Assert.AreEqual(1, cout.Position); cout.WriteInt32NoTag(500); Assert.AreEqual(3, cout.Position); //Field 12: length delimited 120 bytes cout.WriteTag(12, WireFormat.WireType.LengthDelimited); Assert.AreEqual(4, cout.Position); cout.WriteBytesNoTag(ByteString.CopyFrom(content)); Assert.AreEqual(115, cout.Position); // Field 13: fixed numeric value: 501 cout.WriteTag(13, WireFormat.WireType.Fixed32); Assert.AreEqual(116, cout.Position); cout.WriteSFixed32NoTag(501); Assert.AreEqual(120, cout.Position); cout.Flush(); } byte[] bytes = new byte[130]; { CodedOutputStream cout = CodedOutputStream.CreateInstance(bytes); // Field 1: numeric value: 500 cout.WriteTag(1, WireFormat.WireType.Varint); Assert.AreEqual(1, cout.Position); cout.WriteInt32NoTag(500); Assert.AreEqual(3, cout.Position); //Field 2: length delimited 120 bytes cout.WriteTag(2, WireFormat.WireType.LengthDelimited); Assert.AreEqual(4, cout.Position); cout.WriteBytesNoTag(ByteString.CopyFrom(child)); Assert.AreEqual(125, cout.Position); // Field 3: fixed numeric value: 500 cout.WriteTag(3, WireFormat.WireType.Fixed32); Assert.AreEqual(126, cout.Position); cout.WriteSFixed32NoTag(501); Assert.AreEqual(130, cout.Position); cout.Flush(); } //Now test Input stream: { CodedInputStream cin = CodedInputStream.CreateInstance(new MemoryStream(bytes), new byte[50]); uint tag; int intValue = 0; string ignore; Assert.AreEqual(0, cin.Position); // Field 1: Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 1); Assert.AreEqual(1, cin.Position); Assert.IsTrue(cin.ReadInt32(ref intValue) && intValue == 500); Assert.AreEqual(3, cin.Position); //Field 2: Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 2); Assert.AreEqual(4, cin.Position); uint childlen = cin.ReadRawVarint32(); Assert.AreEqual(120u, childlen); Assert.AreEqual(5, cin.Position); int oldlimit = cin.PushLimit((int)childlen); Assert.AreEqual(5, cin.Position); // Now we are reading child message { // Field 11: numeric value: 500 Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 11); Assert.AreEqual(6, cin.Position); Assert.IsTrue(cin.ReadInt32(ref intValue) && intValue == 500); Assert.AreEqual(8, cin.Position); //Field 12: length delimited 120 bytes Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 12); Assert.AreEqual(9, cin.Position); ByteString bstr = null; Assert.IsTrue(cin.ReadBytes(ref bstr) && bstr.Length == 110 && bstr.ToByteArray()[109] == 109); Assert.AreEqual(120, cin.Position); // Field 13: fixed numeric value: 501 Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 13); // ROK - Previously broken here, this returned 126 failing to account for bufferSizeAfterLimit Assert.AreEqual(121, cin.Position); Assert.IsTrue(cin.ReadSFixed32(ref intValue) && intValue == 501); Assert.AreEqual(125, cin.Position); Assert.IsTrue(cin.IsAtEnd); } cin.PopLimit(oldlimit); Assert.AreEqual(125, cin.Position); // Field 3: fixed numeric value: 501 Assert.IsTrue(cin.ReadTag(out tag, out ignore) && tag >> 3 == 3); Assert.AreEqual(126, cin.Position); Assert.IsTrue(cin.ReadSFixed32(ref intValue) && intValue == 501); Assert.AreEqual(130, cin.Position); Assert.IsTrue(cin.IsAtEnd); } }
public abstract void WriteTo(CodedOutputStream output);
/// <summary> /// Creates an instance which writes to the given stream. /// </summary> /// <param name="output">Stream to write messages to.</param> public MessageStreamWriter(Stream output) { codedOutput = CodedOutputStream.CreateInstance(output); }