Ejemplo n.º 1
0
        public static void WriteInt8(sbyte value, MsgPackStream stream)
        {
            if (value < FormatRange.MinFixNegativeInt)
            {
                stream.WriteUInt8(FormatCode.Int8);
            }

            stream.WriteInt8(value);
        }
Ejemplo n.º 2
0
        public static void WriteExtensionHeader(ExtensionHeader header, MsgPackStream stream)
        {
            switch (header.Length)
            {
            case 1: stream.WriteUInt8(FormatCode.FixExt1); break;

            case 2: stream.WriteUInt8(FormatCode.FixExt2); break;

            case 4: stream.WriteUInt8(FormatCode.FixExt4); break;

            case 8: stream.WriteUInt8(FormatCode.FixExt8); break;

            case 16: stream.WriteUInt8(FormatCode.FixExt16); break;

            default:
                if (header.Length <= byte.MaxValue)
                {
                    stream.WriteUInt8(FormatCode.Ext8);
                    stream.WriteUInt8(unchecked ((byte)header.Length));
                }
                else if (header.Length <= ushort.MaxValue)
                {
                    stream.WriteUInt8(FormatCode.Ext16);
                    stream.WriteUInt16(unchecked ((ushort)header.Length));
                }
                else
                {
                    stream.WriteUInt8(FormatCode.Ext32);
                    stream.WriteUInt32(header.Length);
                }

                break;
            }

            stream.WriteInt8(header.TypeCode);
        }