public object Convert(object value, object converterParameter, BinarySerializationContext ctx) { var sector = (uint) value; var iso = ctx.FindAncestor<Iso9660>(); var sectorSize = iso.PrimaryVolumeDescriptor.SectorSize; return sector*sectorSize; }
public void Deserialize(Stream stream, Endianness endianness, BinarySerializationContext serializationContext) { var readByte = stream.ReadByte(); if (readByte == -1) { throw new EndOfStreamException(); } Value = Convert.ToByte(readByte); }
public void Deserialize(Stream Stream, Endianness Endianness, BinarySerializationContext SerializationContext) { var Buffer = new byte[4]; Stream.Read(Buffer); Array.Reverse(Buffer); var TTL = BitConverter.ToUInt32(Buffer); Value = new TimeSpan(0, 0, (int)TTL); }
public void Deserialize(Stream stream, BinarySerialization.Endianness endianness, BinarySerializationContext serializationContext) { var varuint = new Varuint { Value = Value }; varuint.Deserialize(stream, endianness, serializationContext); Value = varuint.Value; }
public void Serialize(Stream stream, Endianness endianness, BinarySerializationContext serializationContext) { if (Values != null) { using var writer = new StreamWriter(stream); var txt = StringUtils.GetString(Values, LineEnding.Linux); writer.Write(txt); writer.Flush(); writer.Close(); } }
public void Serialize(Stream Stream, Endianness Endianness, BinarySerializationContext SerializationContext) { var Seconds = Value.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; var Bytes = BitConverter.GetBytes((uint)Seconds); if (Endianness == Endianness.Big) { Array.Reverse(Bytes); } Stream.Write(Bytes); }
void IBinaryAdapter <FileInfo> .Serialize(BinarySerializationContext <FileInfo> context, FileInfo value) { if (null == value) { context.Writer->Add("null"); } else { context.Writer->Add(value.GetRelativePath()); } }
public void Serialize(Stream stream, BinarySerialization.Endianness endianness, BinarySerializationContext serializationContext) { var writer = new BinaryWriter(stream); writer.Write((ushort)Value.Year); writer.Write((byte)Value.Month); writer.Write((byte)Value.Day); writer.Write((byte)Value.Hour); writer.Write((byte)Value.Minute); writer.Write((byte)Value.Second); writer.Write((ushort)Value.Millisecond); }
public StreamReaderWrapper(Stream stream, BinarySerializationContext context) { _stream = stream; #if !NETSTANDARD2_1_OR_GREATER _buffer = ArrayPool <byte> .Shared.Rent(4096); _handle = GCHandle.Alloc(_buffer, GCHandleType.Pinned); _bufferP = (byte *)_handle.AddrOfPinnedObject().ToPointer(); #endif Context = context; }
/// <summary> /// Initializes a new instance of the BinarySerializationContext class with a parent, parentType, and parentContext. /// </summary> /// <param name="value">The value of the object being serialized.</param> /// <param name="parentValue">The parent of this object in the object graph.</param> /// <param name="parentType">The type of the parent object.</param> /// <param name="parentContext">The parent object serialization context.</param> /// <param name="memberInfo">Member info for this field.</param> internal BinarySerializationContext(object value, object parentValue, Type parentType, BinarySerializationContext parentContext, MemberInfo memberInfo) { Value = value; ParentValue = parentValue; ParentType = parentType; ParentContext = parentContext; MemberInfo = memberInfo; // Deprecated Parent = parentValue; }
public void Serialize(Stream stream, BinarySerialization.Endianness endianness, BinarySerializationContext serializationContext) { if (Value == null) { stream.WriteByte(NullValue); } else { var data = System.Text.Encoding.UTF8.GetBytes(Value); stream.WriteByte((byte)data.Length); stream.Write(data, 0, data.Length); } }
public object Convert(object value, object parameter, BinarySerializationContext ctx) { if (parameter == null) { throw new ArgumentNullException(nameof(parameter), "Must specify a mask."); } var mask = System.Convert.ToInt32(parameter); var operand = System.Convert.ToInt32(value); return(operand & mask); }
private void Save(FlyScene scene, BinarySerializationContext context) { context.WriteDefaultHeader(); context.Write(scene.HalfSize.X); context.Write(scene.HalfSize.Y); context.Write(scene.EntityCount); foreach (IFlyEntity entity in scene.Entities) { context.WriteObject(entity); } }
public void Deserialize(Stream Stream, Endianness Endianness, BinarySerializationContext SerializationContext) { var Buffer = new byte[4]; Stream.Read(Buffer); if (Endianness == Endianness.Big) { Array.Reverse(Buffer); } var Seconds = BitConverter.ToUInt32(Buffer); Value = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(Seconds); }
public void Serialize(Stream stream, Endianness endianness, BinarySerializationContext serializationContext) { var serializer = new BinarySerializer(); serializer.Serialize(stream, Header); foreach (var subHeader in SubHeaders) { serializer.Serialize(stream, subHeader); } foreach (var animation in Animations) { serializer.Serialize(stream, animation); } }
public void Serialize(Stream stream, BinarySerialization.Endianness endianness, BinarySerializationContext context) { var writer = new BinaryWriter(stream); var value = Value; do { var lower7Bits = (byte) (value & 0x7f); value >>= 7; if (value > 0) lower7Bits |= 128; writer.Write(lower7Bits); } while (value > 0); }
public void Deserialize(Stream stream, Endianness endianness, BinarySerializationContext serializationContext) { Offset = DataStream.ReadInt32(stream, endianness); var curPos = stream.Position; //stream.Position += -8; stream.Seek(0, SeekOrigin.Begin); Console.WriteLine(DataStream.ReadUInt32(stream)); stream.Position = Offset; var encodingStr = serializationContext.MemberInfo.CustomAttributes.Where(attr => attr.AttributeType.Name == "FieldEncodingAttribute")?.First().ConstructorArguments[0].Value ?? "ASCII"; String = DataStream.ReadCString(stream, Encoding.GetEncoding((string)encodingStr)); stream.Position = curPos; }
public void Serialize(Stream stream, BinarySerialization.Endianness endianness, BinarySerializationContext serializationContext) { var boundedStream = (BoundedStream)stream; Assert.AreEqual(0, boundedStream.Position); Assert.AreEqual(100, (int)boundedStream.MaxLength.ByteCount); var varuint = new Varuint { Value = Value }; varuint.Serialize(stream, endianness, serializationContext); }
/// <summary> /// This is called by the framework to indicate a new operation. /// </summary> /// <param name="context"></param> protected override void Reset(BinarySerializationContext context) { if (_crc == null) { _crc = new Crc32(Polynomial, InitialValue) { IsDataReflected = IsDataReflected, IsRemainderReflected = IsRemainderReflected, FinalXor = FinalXor }; } _crc.Reset(); }
public void Deserialize(Stream Stream, Endianness Endianness, BinarySerializationContext Context) { var BoundStream = (BoundedStream)Stream; var Packet = GetPacket(BoundStream); var BitStream = new BitStream(Packet, true); BitStream.Seek(BoundStream.GlobalPosition.TotalByteCount, 0); ReadLabels(BitStream); Seek(BoundStream); }
public void Write_Should_use_context_marshalling_When_sub_field() { using Stream stream = new MemoryStream(); using BinarySerializationContext context = new BinarySerializationContext() .Marshal <int, int>(i => i * 2); BinarySerializer.Write(stream, new Point(1, 2), context); stream.Position = 0; Point copy = Read <Point>(stream); Check.That(copy).IsEqualTo(new Point(2, 4)); }
public void Serialize(Stream s, Endianness endianness, BinarySerializationContext context) { var serial = new BinarySerializer(); serial.Serialize(s, Header); serial.Serialize(s, Unk); foreach (var function in Functions) { serial.Serialize(s, function); } while (s.Position < Header.byteSize) { DataStream.WriteInt32(s, 0); } }
public void Serialize(Stream Stream, Endianness Endianness, BinarySerializationContext Context) { var BitMap = (BitMap)Context.ParentContext.Value; var Buffer = new byte[BitMap.Length * 8 + 2]; var BitStream = new BitStream(Buffer, true); for (var I = 0; I < BitMap.Length * 8; I++) { BitStream.WriteBit(Value.Contains((RecordType)(I + BitMap.WindowBlock * 256))); } Stream.Write(BitStream.GetStreamData()); }
public void Write_Should_use_context_marshalling_When_same_type() { using Stream stream = new MemoryStream(); using BinarySerializationContext context = new BinarySerializationContext() .Marshal <int, int>(_ => 1337); BinarySerializer.Write(stream, 42, context); stream.Position = 0; int copy = Read <int>(stream); Check.That(copy).IsEqualTo(1337); }
public void Write_Should_use_context_marshalling_for_object() { using Stream stream = new MemoryStream(); using BinarySerializationContext context = new BinarySerializationContext() .Marshal <int, string>(i => $"value {i}"); BinarySerializer.Write <object>(stream, 42, context); stream.Position = 0; object copy = Read <object>(stream); Check.That(copy).IsInstanceOf <string>().And.IsEqualTo("value 42"); }
public void Serialize(Stream stream, Endianness endianness, BinarySerializationContext serializationContext) { var serializer = new BinarySerializer(); serializer.Serialize(stream, Info); foreach (var setting in Settings) { DataStream.WriteUInt32(stream, setting); } foreach (var motData in Data) { serializer.Serialize(stream, motData); } serializer.Serialize(stream, Bones); }
public void Deserialize(Stream Stream, Endianness Endianness, BinarySerializationContext Context) { while (true) { var Byte = (byte)Stream.ReadByte(); if (Byte == 0) { return; } var LabelType = GetLabelType(Byte); switch (LabelType) { case LabelType.Normal: { var LabelLength = GetLabelLength(Byte); GetLabel(Stream, LabelLength); continue; } case LabelType.Compressed: { var Pointer = GetPointer(Byte, Stream.ReadByte()); var Message = Context.FindAncestor <Message>(); var QLabel = Message.Questions .Select(Question => Question.Domain) .Where(Domain => Domain.Labels.Any(Label => Label.Offset == Pointer)) .SelectMany(Domain => Domain.Labels) .Where(Label => Label.Offset >= Pointer); Labels.AddRange(QLabel); return; } case LabelType.Extended: case LabelType.Unallocated: default: throw new NotImplementedException(Enum.GetName(typeof(LabelType), LabelType)); } } }
public void Serialize(Stream stream, BinarySerialization.Endianness endianness, BinarySerializationContext context) { var value = Value; do { var lower7Bits = (byte)(value & 127); value >>= 7; if (value > 0) { lower7Bits |= 128; } stream.WriteByte(lower7Bits); } while (value > 0); }
public void Deserialize(Stream Stream, Endianness Endianness, BinarySerializationContext Context) { var BitMap = (BitMap)Context.ParentContext.Value; var BitStream = new BitStream(Stream, true); Value = new List <RecordType>(); for (var I = 0; I < BitMap.Length * 8; I++) { if (BitStream.ReadBit()) { Value.Add((RecordType)(I + BitMap.WindowBlock * 256)); } } }
public void Deserialize(Stream Stream, Endianness Endianness, BinarySerializationContext Context) { var MemoryStream = GetRootStream(Stream); var Bytes = MemoryStream.ToArray(); var DnStream = new DnStream(in Bytes); DnStream.Seek((ushort)MemoryStream.Position); Labels = GetLabels(DnStream); var BoundStream = Stream as BoundedStream; BoundStream.Seek(DnStream.BytePosition + 1, SeekOrigin.Begin); }
public object Convert(object value, object parameter, BinarySerializationContext context) { if (value == null) { throw new ArgumentNullException(nameof(value)); } if (parameter == null) { throw new ArgumentNullException(nameof(parameter)); } var v = System.Convert.ToUInt64(value); var m = System.Convert.ToUInt64(parameter); return(v + (m - v % m) % m); }
public object Convert(object value, object parameter, BinarySerializationContext ctx) { var operand = System.Convert.ToInt32(value); if (parameter != null) { var mask = System.Convert.ToInt32(parameter); operand &= mask; } int count; for (count = 0; operand > 0; operand >>= 1) { count += operand & 1; } return(count); }
public void Deserialize(Stream stream, BinarySerialization.Endianness endianness, BinarySerializationContext context) { var reader = new BinaryReader(stream); bool more = true; int shift = 0; Value = 0; while (more) { int b = reader.ReadByte(); if (b == -1) throw new InvalidOperationException("Reached end of stream before end of varuint."); var lower7Bits = (byte)b; more = (lower7Bits & 128) != 0; Value |= (uint)((lower7Bits & 0x7f) << shift); shift += 7; } }
/// <summary> /// Initializes a new instance of the MemberSerializingEventArgs class with the member name. /// </summary> /// <param name="memberName">The name of the member.</param> /// <param name="context">The current serialization context.</param> /// <param name="offset">The current offset in the stream relative to the start of the overall operation.</param> public MemberSerializingEventArgs(string memberName, BinarySerializationContext context, long offset) { MemberName = memberName; Context = context; Offset = offset; }
private object ConvertBack(object value, BinarySerializationContext context) { return ValueConverter.ConvertBack(value, ConverterParameter, context); }
/// <summary> /// Initializes a new instance of the MemberSerializedEventArgs class with the member name and value. /// </summary> /// <param name="memberName">The name of the member.</param> /// <param name="value">The value of the member.</param> /// <param name="context">The current serialization context.</param> /// <param name="offset">The current offset in the stream relative to the start of the overall operation.</param> public MemberSerializedEventArgs(string memberName, object value, BinarySerializationContext context, long offset) : base(memberName, context, offset) { Value = value; }
public void Serialize(Stream stream, BinarySerialization.Endianness endianness, BinarySerializationContext serializationContext) { // TODO check context }
public void Deserialize(Stream stream, BinarySerialization.Endianness endianness, BinarySerializationContext serializationContext) { }
public object Convert(object value, object converterParameter, BinarySerializationContext ctx) { var a = System.Convert.ToDouble(value); return a * 2; }
public object ConvertBack(object value, object converterParameter, BinarySerializationContext ctx) { throw new System.NotImplementedException(); }