public void VisitValue(string value, VisitArgs args) { if (args.Index > 0) { BinaryZPacker.Pack(_writeBuffer, args.Index); } if (value == null) { _writeBuffer.WriteByte(BinaryZPacker.Null); return; } var length = Encoding.GetByteCount(value); if (length < BinaryZPacker.VariabelLength) { _writeBuffer.WriteByte((byte)length); } else { _writeBuffer.WriteByte(BinaryZPacker.VariabelLength); BinaryV32Packer.PackU(_writeBuffer, (uint)value.Length); } var position = _writeBuffer.Advance(length); Encoding.GetBytes(value, 0, value.Length, _writeBuffer.Buffer, position); }
private static void AssertPackS(Int32?value) { using (var stream = new MemoryStream()) { BinaryV32Packer.PackS(stream, value); stream.Seek(0, SeekOrigin.Begin); var actual = BinaryV32Packer.UnpackS(stream); Assert.Equal(value, actual); } }
public void VisitValue(byte[] value, VisitArgs args) { if (args.Index > 0) { BinaryZPacker.Pack(_writeBuffer, args.Index); } if (value == null) { _writeBuffer.WriteByte(BinaryZPacker.Null); return; } if (value.Length < BinaryZPacker.VariabelLength) { _writeBuffer.WriteByte((Byte)value.Length); } else { _writeBuffer.WriteByte(BinaryZPacker.VariabelLength); BinaryV32Packer.PackU(_writeBuffer, (uint)value.Length); } _writeBuffer.Write(value, 0, value.Length); }
/// <summary> /// Makes the value take variable length, it takes as much as it needs ranging from 1-5 bytes /// </summary> /// <param name="nullableValue">The value to pack</param> public void WriteNV(UInt32?nullableValue) { BinaryV32Packer.PackU(_writeBuffer, nullableValue); }
/// <summary> /// Makes the value take variable length, it takes as much as it needs ranging from 1-5 bytes /// </summary> /// <param name="value">The value to pack</param> public void WriteV(UInt32 value) { BinaryV32Packer.PackU(_writeBuffer, value); }
public UInt32?ReadNV() { return(BinaryV32Packer.UnpackU(_stream)); }
public UInt32 ReadV() { return(BinaryV32Packer.UnpackU(_stream) ?? 0); }