Beispiel #1
0
        private void WriteStringHeaderAndLength(IMsgPackWriter writer, int length)
        {
            if (length <= 31)
            {
                writer.Write((byte)(((byte)DataTypes.FixStr + length) % 256));
                return;
            }

            if (length <= byte.MaxValue)
            {
                writer.Write(DataTypes.Str8);
                IntConverter.WriteValue((byte)length, writer);
                return;
            }

            if (length <= ushort.MaxValue)
            {
                writer.Write(DataTypes.Str16);
                IntConverter.WriteValue((ushort)length, writer);
            }
            else
            {
                writer.Write(DataTypes.Str32);
                IntConverter.WriteValue((uint)length, writer);
            }
        }
        protected void WriteMapHeaderAndLength(int length, IMsgPackWriter reader)
        {
            if (length <= 15)
            {
                IntConverter.WriteValue((byte)((byte)DataTypes.FixMap + length), reader);
                return;
            }

            if (length <= ushort.MaxValue)
            {
                reader.Write(DataTypes.Map16);
                IntConverter.WriteValue((ushort)length, reader);
            }
            else
            {
                reader.Write(DataTypes.Map32);
                IntConverter.WriteValue((uint)length, reader);
            }
        }
Beispiel #3
0
        protected void WriteArrayHeaderAndLength(int length, IMsgPackWriter writer)
        {
            if (length <= 15)
            {
                IntConverter.WriteValue((byte)((byte)DataTypes.FixArray + length), writer);
                return;
            }

            if (length <= ushort.MaxValue)
            {
                writer.Write(DataTypes.Array16);
                IntConverter.WriteValue((ushort)length, writer);
            }
            else
            {
                writer.Write(DataTypes.Array32);
                IntConverter.WriteValue((uint)length, writer);
            }
        }
Beispiel #4
0
        private void WriteBinaryHeaderAndLength(int length, IMsgPackWriter writer)
        {
            if (length <= byte.MaxValue)
            {
                writer.Write(DataTypes.Bin8);
                IntConverter.WriteValue((byte)length, writer);
                return;
            }

            if (length <= ushort.MaxValue)
            {
                writer.Write(DataTypes.Bin16);
                IntConverter.WriteValue((ushort)length, writer);
            }
            else
            {
                writer.Write(DataTypes.Bin32);
                IntConverter.WriteValue((uint)length, writer);
            }
        }