public static SerializaType[] SerializeBondObject(this IBondSerializable value) { byte[] result; using (MemoryStream memoryStream = new MemoryStream()) { using (CompactBinaryProtocolWriter compactBinaryProtocolWriter = new CompactBinaryProtocolWriter(memoryStream)) { ((IBondSerializable)value).Write(compactBinaryProtocolWriter); result = memoryStream.ToArray(); } } return(result); }
private static uint ComputeChecksum <T>(Message <T> message, out long size) where T : IBondSerializable, new() { using (var streamWrapper = Pools.MemoryStreamPool.GetInstance()) { var stream = streamWrapper.Instance; using (var writer = new CompactBinaryProtocolWriter(stream, leaveOpen: true)) { message.Payload.Write(writer); var bytes = stream.GetBuffer(); var result = HashCodeHelper.Combine(new ArrayView <byte>(bytes, start: 0, length: (int)stream.Position)); size = stream.Position; return(unchecked ((uint)result)); } } }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { if (value == null) { writer.WriteNull(); return; } byte[] result; using (MemoryStream memoryStream = new MemoryStream()) { using (CompactBinaryProtocolWriter compactBinaryProtocolWriter = new CompactBinaryProtocolWriter(memoryStream)) { ((IBondSerializable)value).Write(compactBinaryProtocolWriter); result = memoryStream.ToArray(); } } string str = Convert.ToBase64String(result); writer.WriteValue(str); }