public static float ReadSingle(MsgPackStream stream) { var code = stream.ReadUInt8(); switch (FormatMask.Match(code)) { case FormatMask.PositiveFixInt: return(code); case FormatMask.NegativeFixInt: return(unchecked ((sbyte)code)); } switch (code) { case FormatCode.Float32: return(stream.ReadSingle()); case FormatCode.Int8: return(stream.ReadInt8()); case FormatCode.UInt8: return(stream.ReadUInt8()); case FormatCode.Int16: return(stream.ReadInt16()); case FormatCode.UInt16: return(stream.ReadUInt16()); case FormatCode.Int32: return(stream.ReadInt32()); case FormatCode.UInt32: return(stream.ReadUInt32()); case FormatCode.Int64: return(stream.ReadInt64()); case FormatCode.UInt64: return(stream.ReadUInt64()); default: throw new MsgPackCodeException(code); } }
public static byte ReadUInt8(MsgPackStream stream) { var code = stream.ReadUInt8(); if (FormatMask.Match(code) == FormatMask.PositiveFixInt) { return(code); } switch (code) { case FormatCode.UInt8: return(stream.ReadUInt8()); default: throw new MsgPackCodeException(code); } }
public static uint ReadMapHeader(MsgPackStream stream) { var code = stream.ReadUInt8(); if (FormatMask.Match(code) == FormatMask.FixMap) { return(code & 0xfu); } switch (code) { case FormatCode.Map16: return(stream.ReadUInt16()); case FormatCode.Map32: return(stream.ReadUInt32()); default: throw new MsgPackCodeException(code); } }
public static sbyte ReadInt8(MsgPackStream stream) { var code = stream.ReadUInt8(); switch (FormatMask.Match(code)) { case FormatMask.PositiveFixInt: case FormatMask.NegativeFixInt: return(unchecked ((sbyte)code)); } switch (code) { case FormatCode.Int8: return(stream.ReadInt8()); case FormatCode.UInt8: return(checked ((sbyte)stream.ReadUInt8())); default: throw new MsgPackCodeException(code); } }
public static BufferSegment ReadUtf8(MsgPackStream stream) { var code = stream.ReadUInt8(); if (FormatMask.Match(code) == FormatMask.FixString) { return(stream.ReadBytes(code & 0x1Fu)); } switch (code) { case FormatCode.Str8: return(stream.ReadBytes(stream.ReadUInt8())); case FormatCode.Str16: return(stream.ReadBytes(stream.ReadUInt16())); case FormatCode.Str32: return(stream.ReadBytes(stream.ReadUInt32())); case FormatCode.Nil: return(new BufferSegment()); default: throw new MsgPackCodeException(code); } }
public static FormatType GetType(MsgPackStream stream) { var code = stream.Peek(); switch (FormatMask.Match(code)) { case FormatMask.PositiveFixInt: return(FormatType.Integer); case FormatMask.NegativeFixInt: return(FormatType.Integer); case FormatMask.FixString: return(FormatType.String); case FormatMask.FixArray: return(FormatType.Array); case FormatMask.FixMap: return(FormatType.Map); } switch (code) { case FormatCode.Nil: return(FormatType.Nil); case FormatCode.NeverUsed: return(FormatType.Unknown); case FormatCode.False: return(FormatType.Boolean); case FormatCode.True: return(FormatType.Boolean); case FormatCode.Int8: return(FormatType.Integer); case FormatCode.UInt8: return(FormatType.Integer); case FormatCode.Int16: return(FormatType.Integer); case FormatCode.UInt16: return(FormatType.Integer); case FormatCode.Int32: return(FormatType.Integer); case FormatCode.UInt32: return(FormatType.Integer); case FormatCode.Int64: return(FormatType.Integer); case FormatCode.UInt64: return(FormatType.Integer); case FormatCode.Float32: return(FormatType.Float); case FormatCode.Float64: return(FormatType.Float); case FormatCode.Str8: return(FormatType.String); case FormatCode.Str16: return(FormatType.String); case FormatCode.Str32: return(FormatType.String); case FormatCode.Bin8: return(FormatType.Binary); case FormatCode.Bin16: return(FormatType.Binary); case FormatCode.Bin32: return(FormatType.Binary); case FormatCode.Array16: return(FormatType.Array); case FormatCode.Array32: return(FormatType.Array); case FormatCode.Map16: return(FormatType.Map); case FormatCode.Map32: return(FormatType.Map); case FormatCode.FixExt1: return(FormatType.Extension); case FormatCode.FixExt2: return(FormatType.Extension); case FormatCode.FixExt4: return(FormatType.Extension); case FormatCode.FixExt8: return(FormatType.Extension); case FormatCode.FixExt16: return(FormatType.Extension); case FormatCode.Ext8: return(FormatType.Extension); case FormatCode.Ext16: return(FormatType.Extension); case FormatCode.Ext32: return(FormatType.Extension); default: return(FormatType.Unknown); } }
public static void Skip(MsgPackStream stream) { var code = stream.ReadUInt8(); switch (FormatMask.Match(code)) { case FormatMask.PositiveFixInt: return; case FormatMask.NegativeFixInt: return; case FormatMask.FixString: stream.Skip(code & 0x1Fu); return; case FormatMask.FixArray: SkipElements(stream, code & 0xFu); return; case FormatMask.FixMap: SkipElements(stream, 2u * (code & 0xFu)); return; } switch (code) { case FormatCode.Nil: return; case FormatCode.False: return; case FormatCode.True: return; case FormatCode.Int8: stream.Skip(1u); break; case FormatCode.UInt8: stream.Skip(1u); break; case FormatCode.Int16: stream.Skip(2u); break; case FormatCode.UInt16: stream.Skip(2u); break; case FormatCode.Int32: stream.Skip(4u); break; case FormatCode.UInt32: stream.Skip(4u); break; case FormatCode.Int64: stream.Skip(8u); break; case FormatCode.UInt64: stream.Skip(8u); break; case FormatCode.Float32: stream.Skip(4u); break; case FormatCode.Float64: stream.Skip(8u); break; case FormatCode.Str8: stream.Skip(stream.ReadUInt8()); break; case FormatCode.Str16: stream.Skip(stream.ReadUInt16()); break; case FormatCode.Str32: stream.Skip(stream.ReadUInt32()); break; case FormatCode.Bin8: stream.Skip(stream.ReadUInt8()); break; case FormatCode.Bin16: stream.Skip(stream.ReadUInt16()); break; case FormatCode.Bin32: stream.Skip(stream.ReadUInt32()); break; case FormatCode.Array16: SkipElements(stream, stream.ReadUInt16()); break; case FormatCode.Array32: SkipElements(stream, stream.ReadUInt32()); break; case FormatCode.Map16: SkipElements(stream, 2u * stream.ReadUInt16()); break; case FormatCode.Map32: SkipElements(stream, 2u * stream.ReadUInt32()); break; case FormatCode.FixExt1: stream.Skip(2u); break; case FormatCode.FixExt2: stream.Skip(3u); break; case FormatCode.FixExt4: stream.Skip(5u); break; case FormatCode.FixExt8: stream.Skip(9u); break; case FormatCode.FixExt16: stream.Skip(17u); break; case FormatCode.Ext8: stream.Skip(1u + stream.ReadUInt8()); break; case FormatCode.Ext16: stream.Skip(1u + stream.ReadUInt16()); break; case FormatCode.Ext32: stream.Skip(1u + stream.ReadUInt32()); break; default: throw new MsgPackCodeException(code); } }
private static string CodeToString(byte code) { switch (FormatMask.Match(code)) { case FormatMask.PositiveFixInt: return("positive fixint"); case FormatMask.NegativeFixInt: return("negative fixint"); case FormatMask.FixString: return("fixstr"); case FormatMask.FixArray: return("fixarray"); case FormatMask.FixMap: return("fixmap"); } switch (code) { case FormatCode.Nil: return("nil"); case FormatCode.False: return("bool (false)"); case FormatCode.True: return("bool (true)"); case FormatCode.Int8: return("int 8"); case FormatCode.UInt8: return("uint 8"); case FormatCode.Int16: return("int 16"); case FormatCode.UInt16: return("uint 16"); case FormatCode.Int32: return("int 32"); case FormatCode.UInt32: return("uint 32"); case FormatCode.Int64: return("int 64"); case FormatCode.UInt64: return("uint 64"); case FormatCode.Float32: return("float 32"); case FormatCode.Float64: return("float 64"); case FormatCode.Str8: return("str 8"); case FormatCode.Str16: return("str 16"); case FormatCode.Str32: return("str 32"); case FormatCode.Bin8: return("bin 8"); case FormatCode.Bin16: return("bin 16"); case FormatCode.Bin32: return("bin 32"); case FormatCode.Array16: return("array 16"); case FormatCode.Array32: return("array 32"); case FormatCode.Map16: return("map 16"); case FormatCode.Map32: return("map 32"); case FormatCode.FixExt1: return("fixext 1"); case FormatCode.FixExt2: return("fixext 2"); case FormatCode.FixExt4: return("fixext 4"); case FormatCode.FixExt8: return("fixext 8"); case FormatCode.FixExt16: return("fixext 16"); case FormatCode.Ext8: return("ext 8"); case FormatCode.Ext16: return("ext 16"); case FormatCode.Ext32: return("ext 32"); default: return(string.Format("unknown 0x{0:x02}", code)); } }