public static int SetRaw(this DealHeader bank, IFigurePacket tostream) { MemoryStream ms = new MemoryStream(); ms.Write(new byte[tostream.SerialPacketOffset], 0, tostream.SerialPacketOffset); BinaryFormatter binform = new BinaryFormatter(); binform.Serialize(ms, bank); tostream.SerialPacket = ms.ToArray(); ms.Dispose(); return(tostream.SerialPacket.Length); }
public int Serialize(IFigurePacket buffor, int offset, int batchSize, FigureFormat serialFormat = FigureFormat.Binary) { if (serialFormat == FigureFormat.Binary) { return(this.SetRaw(buffor)); } else if (serialFormat == FigureFormat.Json) { return(this.SetJson(buffor)); } else { return(-1); } }
public static int SetJson(this DealHeader thdr, IFigurePacket buffor, int offset = 0) { if (offset > 0) { byte[] jsonBytes = Encoding.UTF8.GetBytes(thdr.SetJsonString()); byte[] serialBytes = new byte[jsonBytes.Length + offset]; jsonBytes.CopyTo(serialBytes, offset); buffor.SerialPacket = serialBytes; jsonBytes = null; } else { buffor.SerialPacket = Encoding.UTF8.GetBytes(thdr.SetJsonString()); } return(buffor.SerialPacket.Length); }
public static int SetJson(this DealMessage tmsg, IFigurePacket buffor) { buffor.SerialPacket = Encoding.UTF8.GetBytes(tmsg.SetJsonString()); return(buffor.SerialPacket.Length); }