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); }
public void VisitValue(DateTime?value, VisitArgs args) { if (args.Index > 0) { BinaryZPacker.Pack(_writeBuffer, args.Index); } if (value == null) { _writeBuffer.WriteByte(BinaryZPacker.Null); return; } if (value.Value.Kind != DateTimeKind.Utc) { value = value.Value.ToUniversalTime(); } var length = BinaryPV64Packer.GetSLength(value.Value.Ticks); _writeBuffer.WriteByte(length); var offset = _writeBuffer.Advance(length); BinaryPV64Packer.PackS(_writeBuffer.Buffer, offset, value.Value.Ticks, length); }
public void PackZTest() { const uint value = (uint)0x0FC0D096; var buffer = BinaryZPacker.Pack(value); Assert.True((3 & buffer[0]) == 3); Assert.True(((buffer[0] & 0xFC) & 0x58) == 0x58); var unpacked = BinaryZPacker.Unpack(buffer, 0); Assert.Equal(value, unpacked); }
public void Leave(object level, VisitArgs args) { if (args.IsRoot) { return; } if (level != null) { var reservation = _reservations.Pop(); _writer.Write(reservation); BinaryZPacker.Pack(_writeBuffer, 0); } }
public void VisitValue(byte?value, VisitArgs args) { if (args.Index > 0) { BinaryZPacker.Pack(_writeBuffer, args.Index); } if (value == null) { _writeBuffer.WriteByte(BinaryZPacker.Null); return; } _writeBuffer.WriteByte((Byte)BinaryInformation.Byte.FixedLength); _writeBuffer.WriteByte(value.Value); }
public void VisitValue(Guid?value, VisitArgs args) { if (args.Index > 0) { BinaryZPacker.Pack(_writeBuffer, args.Index); } if (value == null) { _writeBuffer.WriteByte(BinaryZPacker.Null); return; } _writeBuffer.WriteByte((byte)BinaryInformation.Guid.FixedLength); var bytes = BinaryInformation.Guid.Converter.Convert(value.Value); _writeBuffer.Write(bytes, 0, bytes.Length); }
public void VisitValue(short?value, VisitArgs args) { if (args.Index > 0) { BinaryZPacker.Pack(_writeBuffer, args.Index); } if (value == null) { _writeBuffer.WriteByte(BinaryZPacker.Null); return; } var length = BinaryPV64Packer.GetSLength(value.Value); _writeBuffer.WriteByte(length); var offset = _writeBuffer.Advance(length); BinaryPV64Packer.PackS(_writeBuffer.Buffer, offset, value.Value, length); }
public void Visit(object level, VisitArgs args) { if (args.Index > 0) { BinaryZPacker.Pack(_writeBuffer, args.Index); } if (level == null) { _writeBuffer.WriteByte(BinaryZPacker.Null); return; } _writeBuffer.WriteByte(BinaryZPacker.VariabelLength); if (args.IsRoot) { return; } _reservations.Push(_writer.Reserve()); }
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); }
//public void Write(WriteReservation reservation, UInt32 value) //{ // var currentPosition = _stream.Position; // _stream.Seek(reservation.Position, SeekOrigin.Begin); // Write(value); // _stream.Seek(currentPosition, SeekOrigin.Begin); //} /// <summary> /// More tightly packed than the V version but the max size is 1/4 of an <see cref="UInt32"/> /// </summary> /// <param name="value">The value to pack</param> public void WriteZ(UInt32 value) { BinaryZPacker.Pack(_writeBuffer, value); }
public UInt32 ReadZ() { return(BinaryZPacker.Unpack(_stream)); }