public void WriteCRC16Test() { var bytes = new byte[4096]; var data = "5B000000480000008510010133EFB8010000000000270F0133EFB832303138303932303132372E302E302E31000000000000000000000000000000000000000000000003296A915D".ToHexBytes(); JT809MessagePackWriter jT809MessagePackWriter = new JT809MessagePackWriter(bytes); jT809MessagePackWriter.WriteArray(data); jT809MessagePackWriter.WriteEncode(); var result = jT809MessagePackWriter.FlushAndGetEncodingArray(); Assert.Equal(data, result); }
public byte[] Serialize <T>(T obj, int minBufferSize = 4096) { byte[] buffer = JT809ArrayPool.Rent(minBufferSize); try { JT809MessagePackWriter jT809MessagePackWriter = new JT809MessagePackWriter(buffer); JT809MessagePackFormatterExtensions.GetFormatter <T>().Serialize(ref jT809MessagePackWriter, obj, jT809Config); return(jT809MessagePackWriter.FlushAndGetEncodingArray()); } finally { JT809ArrayPool.Return(buffer); } }
public byte[] Serialize(JT809Package jT809Package, int minBufferSize = 4096) { byte[] buffer = JT809ArrayPool.Rent(minBufferSize); try { JT809MessagePackWriter jT809MessagePackWriter = new JT809MessagePackWriter(buffer); JT809PackageFormatter.Instance.Serialize(ref jT809MessagePackWriter, jT809Package, jT809Config); return(jT809MessagePackWriter.FlushAndGetEncodingArray()); } finally { JT809ArrayPool.Return(buffer); } }