public void Write(PacketSize value, IMsgPackWriter writer)
        {
            writer.Write(DataTypes.UInt32);

            var binary = new UIntBinary(value.Value);

            byte[] bytes;
            if (BitConverter.IsLittleEndian)
            {
                bytes = new[]
                {
                    binary.byte3,
                    binary.byte2,
                    binary.byte1,
                    binary.byte0
                };
            }
            else
            {
                bytes = new[]
                {
                    binary.byte0,
                    binary.byte1,
                    binary.byte2,
                    binary.byte3,
                };
            }

            writer.Write(bytes);
        }
示例#2
0
 internal static void WriteValue(uint item, IMsgPackWriter writer)
 {
     writer.Write((byte)((item >> 24) % 256));
     writer.Write((byte)((item >> 16) % 256));
     writer.Write((byte)((item >> 8) % 256));
     writer.Write((byte)(item % 256));
 }
示例#3
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);
            }
        }
示例#4
0
 public static void WriteUShortValue(ushort value, IMsgPackWriter writer)
 {
     unchecked
     {
         writer.Write((byte)((value >> 8) & 0xff));
         writer.Write((byte)(value & 0xff));
     }
 }
示例#5
0
 private static void WriteShortValue(short value, IMsgPackWriter writer)
 {
     unchecked
     {
         writer.Write((byte)((value >> 8) & 0xff));
         writer.Write((byte)(value & 0xff));
     }
 }
示例#6
0
 private static void WriteIntValue(int value, IMsgPackWriter writer)
 {
     unchecked
     {
         writer.Write((byte)((value >> 24) & 0xff));
         writer.Write((byte)((value >> 16) & 0xff));
         writer.Write((byte)((value >> 8) & 0xff));
         writer.Write((byte)(value & 0xff));
     }
 }
示例#7
0
 public void Write(byte value, IMsgPackWriter writer)
 {
     // positive fixnum
     if (value < 128L)
     {
         writer.Write(value);
     }
     else
     {
         writer.Write(DataTypes.UInt8);
         WriteByteValue(value, writer);
     }
 }
示例#8
0
        public void Write(float value, IMsgPackWriter writer)
        {
            var binary = new FloatBinary(value);

            byte[] bytes;
            if (BitConverter.IsLittleEndian)
            {
                bytes = new[]
                {
                    (byte)DataTypes.Single,
                    binary.byte3,
                    binary.byte2,
                    binary.byte1,
                    binary.byte0
                };
            }
            else
            {
                bytes = new[]
                {
                    (byte)DataTypes.Single,
                    binary.byte0,
                    binary.byte1,
                    binary.byte2,
                    binary.byte3
                };
            }

            writer.Write(bytes);
        }
示例#9
0
 private void WriteImageInfoBody(IImageInfo value, IMsgPackWriter writer)
 {
     _intConverter.Value.Write(value.Width, writer);
     _intConverter.Value.Write(value.Height, writer);
     _stringConverter.Value.Write(value.Link, writer);
     writer.Write(DataTypes.Null);
     _stringConverter.Value.Write(value.Credits, writer);
 }
示例#10
0
        private static bool TryWriteSignedFixNum(long value, IMsgPackWriter writer)
        {
            // positive fixnum
            if (value >= 0 && value < 128L)
            {
                writer.Write(unchecked ((byte)value));
                return(true);
            }

            // negative fixnum
            if (value >= -32L && value <= -1L)
            {
                writer.Write(unchecked ((byte)value));
                return(true);
            }

            return(false);
        }
示例#11
0
 private void WriteBinaryHeaderAndLength(uint length, IMsgPackWriter writer)
 {
     if (length <= byte.MaxValue)
     {
         writer.Write(DataTypes.Bin8);
         NumberConverter.WriteByteValue((byte)length, writer);
     }
     else if (length <= ushort.MaxValue)
     {
         writer.Write(DataTypes.Bin16);
         NumberConverter.WriteUShortValue((ushort)length, writer);
     }
     else
     {
         writer.Write(DataTypes.Bin32);
         NumberConverter.WriteUIntValue(length, writer);
     }
 }
示例#12
0
 internal static void WriteValue(ulong item, IMsgPackWriter writer)
 {
     writer.Write((byte)((item >> 56) % 256));
     writer.Write((byte)((item >> 48) % 256));
     writer.Write((byte)((item >> 40) % 256));
     writer.Write((byte)((item >> 32) % 256));
     writer.Write((byte)((item >> 24) % 256));
     writer.Write((byte)((item >> 16) % 256));
     writer.Write((byte)((item >> 8) % 256));
     writer.Write((byte)(item % 256));
 }
        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);
            }
        }
示例#14
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);
            }
        }
示例#15
0
        private static bool TryWriteUInt32(ulong value, IMsgPackWriter writer)
        {
            if (value > uint.MaxValue)
            {
                return(false);
            }

            writer.Write(DataTypes.UInt32);
            WriteUIntValue((uint)value, writer);
            return(true);
        }
示例#16
0
        private static bool TryWriteUnsignedFixNum(ulong value, IMsgPackWriter writer)
        {
            // positive fixnum
            if (value < 128L)
            {
                writer.Write(unchecked ((byte)value));
                return(true);
            }

            return(false);
        }
示例#17
0
        private static bool TryWriteInt32(long value, IMsgPackWriter writer)
        {
            if (value > int.MaxValue || value < int.MinValue)
            {
                return(false);
            }

            writer.Write(DataTypes.Int32);
            WriteIntValue((int)value, writer);
            return(true);
        }
示例#18
0
        private static bool TryWriteInt8(long value, IMsgPackWriter writer)
        {
            if (value > sbyte.MaxValue || value < sbyte.MinValue)
            {
                return(false);
            }

            writer.Write(DataTypes.Int8);
            WriteSByteValue((sbyte)value, writer);
            return(true);
        }
示例#19
0
        private static bool TryWriteUInt16(ulong value, IMsgPackWriter writer)
        {
            if (value > ushort.MaxValue)
            {
                return(false);
            }

            writer.Write(DataTypes.UInt16);
            WriteUShortValue((ushort)value, writer);
            return(true);
        }
示例#20
0
        private static bool TryWriteInt16(long value, IMsgPackWriter writer)
        {
            if (value < short.MinValue || value > short.MaxValue)
            {
                return(false);
            }

            writer.Write(DataTypes.Int16);
            WriteShortValue((short)value, writer);
            return(true);
        }
示例#21
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);
            }
        }
示例#22
0
        private static bool TryWriteUInt8(ulong value, IMsgPackWriter writer)
        {
            if (value > byte.MaxValue)
            {
                return(false);
            }

            writer.Write(DataTypes.UInt8);
            WriteByteValue((byte)value, writer);
            return(true);
        }
示例#23
0
        public void Write(Beer value, IMsgPackWriter writer)
        {
            if (value == null)
            {
                _context.NullConverter.Write(null, writer);
                return;
            }

            writer.WriteMapHeader(4);
            writer.Write(_brand);
            _stringConverter.Write(value.Brand, writer);

            writer.Write(_sort);
            _listStringConverter.Write(value.Sort, writer);

            writer.Write(_alcohol);
            _floatConverter.Write(value.Alcohol, writer);

            writer.Write(_brewery);
            _stringConverter.Write(value.Brewery, writer);
        }
 private void WriteImplementation(IImageInfo value, IMsgPackWriter writer)
 {
     if (value == null)
     {
         writer.Write(DataTypes.Null);
     }
     else
     {
         writer.WriteMapHeader(4U);
         WriteImageInfoBody(value, writer);
     }
 }
示例#25
0
        public void Write(byte[] value, IMsgPackWriter writer, MsgPackContext context)
        {
            if (value == null)
            {
                context.NullConverter.Write(value, writer, context);
                return;
            }

            WriteBinaryHeaderAndLength(value.Length, writer);

            writer.Write(value);
        }
示例#26
0
 private static void WriteULongValue(ulong value, IMsgPackWriter writer)
 {
     unchecked
     {
         writer.Write((byte)((value >> 56) & 0xff));
         writer.Write((byte)((value >> 48) & 0xff));
         writer.Write((byte)((value >> 40) & 0xff));
         writer.Write((byte)((value >> 32) & 0xff));
         writer.Write((byte)((value >> 24) & 0xff));
         writer.Write((byte)((value >> 16) & 0xff));
         writer.Write((byte)((value >> 8) & 0xff));
         writer.Write((byte)(value & 0xff));
     }
 }
示例#27
0
 public void Write(InnerClass value, IMsgPackWriter writer)
 {
     if (value == null)
     {
         writer.Write(DataTypes.Null);
     }
     else
     {
         writer.WriteMapHeader(1U);
         _stringConverter.Value.Write("Qwer", writer);
         _stringConverter.Value.Write(value.B, writer);
     }
 }
示例#28
0
        public void Write(RequestId value, IMsgPackWriter writer)
        {
            writer.Write(DataTypes.UInt64);

            var binary = new ULongBinary(value.Value);

            byte[] bytes;
            if (BitConverter.IsLittleEndian)
            {
                bytes = new[]
                {
                    binary.byte7,
                    binary.byte6,
                    binary.byte5,
                    binary.byte4,
                    binary.byte3,
                    binary.byte2,
                    binary.byte1,
                    binary.byte0
                };
            }
            else
            {
                bytes = new[]
                {
                    binary.byte0,
                    binary.byte1,
                    binary.byte2,
                    binary.byte3,
                    binary.byte4,
                    binary.byte5,
                    binary.byte6,
                    binary.byte7
                };
            }

            writer.Write(bytes);
        }
示例#29
0
        public void Write(string value, IMsgPackWriter writer)
        {
            if (value == null)
            {
                _context.NullConverter.Write(value, writer);
                return;
            }

            var data = Utf8.GetBytes(value);

            WriteStringHeaderAndLength(writer, data.Length);

            writer.Write(data);
        }
示例#30
0
        public void Write(string value, IMsgPackWriter writer, MsgPackContext context)
        {
            if (value == null)
            {
                context.NullConverter.Write(value, writer, context);
                return;
            }

            var data = Encoding.UTF8.GetBytes(value);

            WriteStringHeaderAndLength(writer, data.Length);

            writer.Write(data);
        }