public static void RunExample() { SequenceBuilder builder = new SequenceBuilder("textureChanger"); builder.Append(VP.Adone().Texture("stone1.jpg", targetName: "myPp01"), TimeSpan.FromSeconds(1)); builder.Append(VP.Adone().Texture("stone2.jpg", targetName: "myPp01"), TimeSpan.FromSeconds(1)); builder.Append(VP.Adone().Texture("stone3.jpg", targetName: "myPp01"), TimeSpan.FromSeconds(1)); foreach (Action action in builder.Build().ToActions()) { Console.WriteLine(action); } }
public void SetKeyRaw(ReadOnlySpan<byte> key) { #if DEBUG Debug.Assert(!didKey, "Key can only be set once"); Debug.Assert(!didBody, "Key must be set before accessing the body"); didKey = true; #endif AllocateExtras(); if (key.Length > Protocol.MaxKeyLength) throw new ArgumentException($"Key is too long; was {key.Length}, maximum is {Protocol.MaxKeyLength}"); keyLength = (ushort)key.Length; bodyBuilder.Append(key); }
public void ReadUInt32_GivenSequenceWithMultipleSegmentsAndNonZeroStart_ShouldGiveExceptedResult(long start, params byte[][] testPath) { //Arrange var sequenceBuilder = new SequenceBuilder <byte>(); foreach (var array in testPath) { sequenceBuilder.Append(array); } var sequence = sequenceBuilder.Build(); //Act var actual = sequence.ReadUInt32(start, true); //Assert const uint expected = 0x02030405; actual.Should().Be(expected); }
private uint DoSerialize(SequenceBuilder output, object?value) { if (value is byte[] tmpByteArray) { #pragma warning disable IDE0067 // nothing to dispose new SegmentedStream(output).Write(tmpByteArray, 0, tmpByteArray.Length); #pragma warning restore IDE0067 return(RawDataFlag); } TypeCode code; if (value == null) { code = TypeCode.DBNull; } else { code = Type.GetTypeCode(value.GetType()); #pragma warning disable IDE0049 // readability switch (code) { case TypeCode.Empty: case TypeCode.DBNull: break; case TypeCode.Object: new BinaryFormatter().Serialize(new SegmentedStream(output), value); break; case TypeCode.String: var theString = (string)value; if (theString.Length > 0) { Utf8NoBom.GetBytes(theString.AsSpan(), output.Request(Utf8NoBom.GetByteCount(theString)).Span); } break; case TypeCode.SByte: output.Request(sizeof(SByte)).Span[0] = (Byte)(SByte)value; break; case TypeCode.Byte: output.Request(sizeof(Byte)).Span[0] = (Byte)value; break; case TypeCode.Boolean: output.Request(sizeof(Byte)).Span[0] = (Boolean)value ? TRUE : FALSE; break; case TypeCode.Char: BinaryPrimitives.WriteUInt16LittleEndian(output.Request(sizeof(Char)).Span, (Char)value); break; case TypeCode.Int16: BinaryPrimitives.WriteInt16LittleEndian(output.Request(sizeof(Int16)).Span, (Int16)value); break; case TypeCode.Int32: BinaryPrimitives.WriteInt32LittleEndian(output.Request(sizeof(Int32)).Span, (Int32)value); break; case TypeCode.Int64: BinaryPrimitives.WriteInt64LittleEndian(output.Request(sizeof(Int64)).Span, (Int64)value); break; case TypeCode.UInt16: BinaryPrimitives.WriteUInt16LittleEndian(output.Request(sizeof(UInt16)).Span, (UInt16)value); break; case TypeCode.UInt32: BinaryPrimitives.WriteUInt32LittleEndian(output.Request(sizeof(UInt32)).Span, (UInt32)value); break; case TypeCode.UInt64: BinaryPrimitives.WriteUInt64LittleEndian(output.Request(sizeof(UInt64)).Span, (UInt64)value); break; case TypeCode.DateTime: BinaryPrimitives.WriteInt64LittleEndian(output.Request(sizeof(Int64)).Span, ((DateTime)value).ToBinary()); break; case TypeCode.Single: #if !(NETSTANDARD2_0 || NET471 || NET472 || NET48) BitConverter.TryWriteBytes(output.Request(sizeof(Single)).Span, (Single)value); #else var float_bytes = BitConverter.GetBytes((Single)value); output.Append(float_bytes.AsSpan()); #endif break; case TypeCode.Double: #if !(NETSTANDARD2_0 || NET471 || NET472 || NET48) BitConverter.TryWriteBytes(output.Request(sizeof(Double)).Span, (Double)value); #else var double_bytes = BitConverter.GetBytes((Double)value); output.Append(double_bytes.AsSpan()); #endif break; case TypeCode.Decimal: var src = Decimal.GetBits((Decimal)value); var target = output.Request(sizeof(Int32) * 4).Span; BinaryPrimitives.WriteInt32LittleEndian(target, src[0]); BinaryPrimitives.WriteInt32LittleEndian(target.Slice(sizeof(Int32)), src[1]); BinaryPrimitives.WriteInt32LittleEndian(target.Slice(sizeof(Int32) + sizeof(Int32)), src[2]); BinaryPrimitives.WriteInt32LittleEndian(target.Slice(sizeof(Int32) + sizeof(Int32) + sizeof(Int32)), src[3]); break; default: throw new SerializationException($"Cannot serialize '{value}', unknown TypeCode: {code}"); } #pragma warning restore IDE0049 } return(FlagPrefix | (uint)code); }