public void Encode<T>(T obj) { var bytes = (byte[])(object) obj; if (bytes == null) throw new InvalidDataException("input must be byte array"); if (_codec._multicodec) _stream.Write(_codec.Header, 0, _codec.Header.Length); MessageIo.WriteMessage(_stream, bytes, flush: true); }
public void Encode<T>(T obj) { if (_codec._multicodec) _stream.Write(_codec.Header, 0, _codec.Header.Length); if (_codec._msgio) { MessageIo.WriteMessage(_stream, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj, Formatting.None))); } else { var bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj, Formatting.None) + '\n'); _stream.Write(bytes, 0, bytes.Length); } }
public void Encode <T>(T obj) { if (_codec._multicodec) { _stream.Write(_codec.Header, 0, _codec.Header.Length); } if (_codec._msgio) { MessageIo.WriteMessage(_stream, Serialize(obj)); } else { ProtoBuf.Serializer.SerializeWithLengthPrefix(_stream, obj, PrefixStyle.Fixed32BigEndian); } _stream.Flush(); }