public static byte[] ToByteArray(IProtoBuf protobuf) { unsafe { byte[] numArray = new byte[protobuf.GetSerializedSize()]; protobuf.Serialize(new MemoryStream(numArray)); return(numArray); } }
public static byte[] ToByteArray(IProtoBuf protobuf) { uint serializedSize = protobuf.GetSerializedSize(); byte[] array = new byte[serializedSize]; MemoryStream stream = new MemoryStream(array); protobuf.Serialize(stream); return(array); }
public override byte[] Encode() { if (this.Body is IProtoBuf) { IProtoBuf body = (IProtoBuf)this.Body; this.Size = (int)body.GetSerializedSize(); byte[] destinationArray = new byte[(this.Size + 4) + 4]; Array.Copy(BitConverter.GetBytes(this.Type), 0, destinationArray, 0, 4); Array.Copy(BitConverter.GetBytes(this.Size), 0, destinationArray, 4, 4); body.Serialize(new MemoryStream(destinationArray, 8, this.Size)); return(destinationArray); } return(null); }
public override byte[] Encode() { if (!(this.body is IProtoBuf)) { return(null); } IProtoBuf protoBuf = (IProtoBuf)this.body; int serializedSize = (int)this.header.GetSerializedSize(); int serializedSize2 = (int)protoBuf.GetSerializedSize(); byte[] array = new byte[2 + serializedSize + serializedSize2]; array[0] = (byte)(serializedSize >> 8 & 255); array[1] = (byte)(serializedSize & 255); this.header.Serialize(new MemoryStream(array, 2, serializedSize)); protoBuf.Serialize(new MemoryStream(array, 2 + serializedSize, serializedSize2)); return(array); }
public override byte[] Encode() { if (!(this.body is IProtoBuf)) { return(null); } IProtoBuf body = (IProtoBuf)this.body; int serializedSize = (int)this.header.GetSerializedSize(); int count = (int)body.GetSerializedSize(); byte[] buffer = new byte[(2 + serializedSize) + count]; buffer[0] = (byte)((serializedSize >> 8) & 0xff); buffer[1] = (byte)(serializedSize & 0xff); this.header.Serialize(new MemoryStream(buffer, 2, serializedSize)); body.Serialize(new MemoryStream(buffer, 2 + serializedSize, count)); return(buffer); }