public void ReadBuffer() { var output = BebopReader.From(_testBuffer); _ = output.ReadByte(); _ = output.ReadInt16(); _ = output.ReadInt32(); _ = output.ReadString(); _ = output.ReadGuid(); }
public void Read() { var output = BebopReader.From(_testBuffer); _ = output.ReadString(); }
public static Library Decode(ImmutableArray <byte> record) { var reader = BebopReader.From(record); return(__DecodeFrom(ref reader)); }
public static T DecodeAs <T>(ImmutableArray <byte> record) where T : BaseLibrary, new() { var reader = BebopReader.From(record); return(__DecodeFrom <T>(ref reader)); }
public static Library Decode(System.ArraySegment <byte> record) { var reader = BebopReader.From(record); return(__DecodeFrom(ref reader)); }
public static T DecodeAs <T>(System.ArraySegment <byte> record) where T : BaseLibrary, new() { var reader = BebopReader.From(record); return(__DecodeFrom <T>(ref reader)); }
public static Library Decode(System.ReadOnlyMemory <byte> record) { var reader = BebopReader.From(record); return(__DecodeFrom(ref reader)); }
public static Library Decode(byte[] record) { var reader = BebopReader.From(record); return(__DecodeFrom(ref reader)); }
public void WriteRead() { var testBytes = new byte[] { 0x1, 0x2, 0x3 }; var testFloats = new float[] { float.MinValue, float.MaxValue }; var testDoubles = new double[] { double.MinValue, double.MaxValue }; var testGuid = Guid.Parse("81c6987b-48b7-495f-ad01-ec20cc5f5be1"); const string testString = @"Hello 明 World!😊"; var testDate = DateTime.UtcNow; var input = BebopWriter.Create(); input.WriteByte(false); input.WriteByte(byte.MaxValue); input.WriteUInt16(ushort.MaxValue); input.WriteInt16(short.MaxValue); input.WriteUInt32(uint.MaxValue); input.WriteInt32(int.MaxValue); input.WriteUInt64(ulong.MaxValue); input.WriteInt64(long.MaxValue); input.WriteFloat32(float.MaxValue); input.WriteFloat64(double.MaxValue); input.WriteFloat32S(testFloats); input.WriteFloat64S(testDoubles); input.WriteString(testString); input.WriteGuid(testGuid); input.WriteDate(testDate); input.WriteBytes(testBytes); input.WriteEnum(TestEnum.Ok); var output = BebopReader.From(input.ToImmutableArray()); // test byte Assert.AreEqual(0, output.ReadByte()); Assert.AreEqual(byte.MaxValue, output.ReadByte()); // test short Assert.AreEqual(ushort.MaxValue, output.ReadUInt16()); Assert.AreEqual(short.MaxValue, output.ReadInt16()); // test int Assert.AreEqual(uint.MaxValue, output.ReadUInt32()); Assert.AreEqual(int.MaxValue, output.ReadInt32()); // test long Assert.AreEqual(ulong.MaxValue, output.ReadUInt64()); Assert.AreEqual(long.MaxValue, output.ReadInt64()); // test float / double Assert.AreEqual(float.MaxValue, output.ReadFloat32()); Assert.AreEqual(double.MaxValue, output.ReadFloat64()); // test float array var floatArrayLength = output.ReadUInt32(); Assert.AreEqual(testFloats.Length, floatArrayLength); var parsedFloats = new float[floatArrayLength]; for (int i = 0; i < floatArrayLength; i++) { parsedFloats[i] = output.ReadFloat32(); } CollectionAssert.AreEqual(testFloats, parsedFloats); // test double array var doubleArrayLength = output.ReadUInt32(); Assert.AreEqual(testDoubles.Length, doubleArrayLength); var parsedDoubles = new double[doubleArrayLength]; for (int i = 0; i < doubleArrayLength; i++) { parsedDoubles[i] = output.ReadFloat64(); } CollectionAssert.AreEqual(testDoubles, parsedDoubles); // test string Assert.AreEqual(testString, output.ReadString()); // test guid Assert.AreEqual(testGuid, output.ReadGuid()); // test date Assert.AreEqual(testDate, output.ReadDate()); // test byte array CollectionAssert.AreEqual(testBytes, output.ReadBytes()); // test enum Assert.AreEqual(TestEnum.Ok, output.ReadEnum <TestEnum>()); Assert.Pass(); }