private object Read(UbjsonMarker m) { for (;;) { switch (m) { case UbjsonMarker.Null: return null; case UbjsonMarker.Noop: m = (UbjsonMarker)stm.ReadByte(); break; case UbjsonMarker.False: return false; case UbjsonMarker.True: return true; case UbjsonMarker.Int8: return (sbyte)ReadInteger(stm, 1); case UbjsonMarker.UInt8: return (byte)ReadInteger(stm, 1); case UbjsonMarker.Int16: return (short)ReadInteger(stm, 2); case UbjsonMarker.Int32: return (int) ReadInteger(stm, 4); case UbjsonMarker.Int64: return (long) ReadInteger(stm, 8); case UbjsonMarker.Float32: return BitConverter.ToSingle(ReadFloatBits(4), 0); case UbjsonMarker.Float64: return BitConverter.ToDouble(ReadFloatBits(8), 0); case UbjsonMarker.String: return ReadString(); case UbjsonMarker.Array: return ReadArray(); case UbjsonMarker.Object: return ReadObject(); default: throw new NotSupportedException(string.Format("Unknown marker {0}.", (char)m)); } } }
private uint ReadLength(UbjsonMarker m) { return(m switch { UbjsonMarker.Int8 => (byte)ReadInteger(stm, 1), UbjsonMarker.UInt8 => (byte)ReadInteger(stm, 1), UbjsonMarker.Int16 => (ushort)ReadInteger(stm, 2), UbjsonMarker.Int32 => (uint)ReadInteger(stm, 4), _ => throw new NotSupportedException(), });
private uint ReadLength(UbjsonMarker m) { switch (m) { case UbjsonMarker.Int8: return((byte)ReadInteger(stm, 1)); case UbjsonMarker.UInt8: return((byte)ReadInteger(stm, 1)); case UbjsonMarker.Int16: return((ushort)ReadInteger(stm, 2)); case UbjsonMarker.Int32: return((uint)ReadInteger(stm, 4)); } throw new NotSupportedException(); }
private void WriteArray(IEnumerable e, int c, UbjsonMarker elementType, Action <object, Stream> writer) { stm.WriteByte((byte)UbjsonMarker.Array); if (elementType != UbjsonMarker.None) { stm.WriteByte((byte)UbjsonMarker.ElementType); stm.WriteByte((byte)elementType); } stm.WriteByte((byte)UbjsonMarker.ElementCount); WriteNumber(c); foreach (var item in e) { writer(item, stm); } }
private object?Read(UbjsonMarker m) { for (;;) { switch (m) { case UbjsonMarker.Null: return(null); case UbjsonMarker.Noop: m = (UbjsonMarker)stm.ReadByte(); break; case UbjsonMarker.False: return(false); case UbjsonMarker.True: return(true); case UbjsonMarker.Int8: return((sbyte)ReadInteger(stm, 1)); case UbjsonMarker.UInt8: return((byte)ReadInteger(stm, 1)); case UbjsonMarker.Int16: return((short)ReadInteger(stm, 2)); case UbjsonMarker.Int32: return((int)ReadInteger(stm, 4)); case UbjsonMarker.Int64: return((long)ReadInteger(stm, 8)); case UbjsonMarker.Float32: return(BitConverter.ToSingle(ReadFloatBits(4), 0)); case UbjsonMarker.Float64: return(BitConverter.ToDouble(ReadFloatBits(8), 0)); case UbjsonMarker.String: return(ReadString()); case UbjsonMarker.Array: return(ReadArray()); case UbjsonMarker.Object: return(ReadObject()); default: throw new NotSupportedException(string.Format("Unknown marker {0}.", (char)m)); } } }
private uint ReadLength(UbjsonMarker m) { switch(m) { case UbjsonMarker.Int8: return (byte)ReadInteger(stm, 1); case UbjsonMarker.UInt8: return (byte)ReadInteger(stm, 1); case UbjsonMarker.Int16: return (ushort)ReadInteger(stm, 2); case UbjsonMarker.Int32: return (uint)ReadInteger(stm, 4); } throw new NotSupportedException(); }