Пример #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);
            }
        }
        public void Write(DateTime value, IMsgPackWriter writer, MsgPackContext context)
        {
            var longValue     = DateTimeUtils.FromDateTime(value);
            var longConverter = context.GetConverter <long>();

            longConverter.Write(longValue, writer, context);
        }
Пример #3
0
        public void Write(ushort value, IMsgPackWriter writer, MsgPackContext context)
        {
            switch (value.GetFormatType())
            {
            case DataTypes.PositiveFixNum:
                WritePositiveFixNum((byte)value, writer);
                break;

            case DataTypes.NegativeFixNum:
                WriteNegativeFixNum((sbyte)value, writer);
                break;

            case DataTypes.UInt8:
                WriteMPackValue((byte)value, writer);
                break;

            case DataTypes.Int8:
                WriteMPackValue((sbyte)value, writer);
                break;

            case DataTypes.UInt16:
                WriteMPackValue(value, writer);
                break;

            case DataTypes.Int16:
                WriteMPackValue((short)value, writer);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #4
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));
 }
Пример #5
0
        private static void WriteNonNegativeInteger(ulong value, IMsgPackWriter writer)
        {
            if (TryWriteUnsignedFixNum(value, writer))
            {
                return;
            }

            if (TryWriteUInt8(value, writer))
            {
                return;
            }

            if (TryWriteUInt16(value, writer))
            {
                return;
            }

            if (TryWriteUInt32(value, writer))
            {
                return;
            }

            if (TryWriteUInt64(value, writer))
            {
                return;
            }

            throw ExceptionUtils.IntSerializationFailure(value);
        }
        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);
        }
Пример #7
0
        public void Write(double value, IMsgPackWriter writer, MsgPackContext context)
        {
            var binary = new DoubleBinary(value);

            writer.Write(DataTypes.Double);
            if (BitConverter.IsLittleEndian)
            {
                writer.Write(binary.byte7);
                writer.Write(binary.byte6);
                writer.Write(binary.byte5);
                writer.Write(binary.byte4);
                writer.Write(binary.byte3);
                writer.Write(binary.byte2);
                writer.Write(binary.byte1);
                writer.Write(binary.byte0);
            }
            else
            {
                writer.Write(binary.byte0);
                writer.Write(binary.byte1);
                writer.Write(binary.byte2);
                writer.Write(binary.byte3);
                writer.Write(binary.byte4);
                writer.Write(binary.byte5);
                writer.Write(binary.byte6);
                writer.Write(binary.byte7);
            }
        }
Пример #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);
        }
        public void Write(UpdateOperation <T> value, IMsgPackWriter writer)
        {
            writer.WriteArrayHeader(3);

            _stringConverter.Write(value.OperationType, writer);
            _intConverter.Write(value.FieldNumber, writer);
            _argumentConverter.Write(value.Argument, writer);
        }
Пример #10
0
 public static void WriteUShortValue(ushort value, IMsgPackWriter writer)
 {
     unchecked
     {
         writer.Write((byte)((value >> 8) & 0xff));
         writer.Write((byte)(value & 0xff));
     }
 }
Пример #11
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);
 }
Пример #12
0
 private static void WriteShortValue(short value, IMsgPackWriter writer)
 {
     unchecked
     {
         writer.Write((byte)((value >> 8) & 0xff));
         writer.Write((byte)(value & 0xff));
     }
 }
        public void Write(StringSliceOperation value, IMsgPackWriter writer)
        {
            writer.WriteArrayHeader(5);

            _stringConverter.Write(value.OperationType, writer);
            _intConverter.Write(value.FieldNumber, writer);
            _intConverter.Write(value.Position, writer);
            _intConverter.Write(value.Offset, writer);
            _stringConverter.Write(value.Argument, writer);
        }
        public void Write(InsertReplaceRequest <T> value, IMsgPackWriter writer)
        {
            writer.WriteMapHeader(2);

            _keyConverter.Write(Key.SpaceId, writer);
            _uintConverter.Write(value.SpaceId, writer);

            _keyConverter.Write(Key.Tuple, writer);
            _tupleConverter.Write(value.Tuple, writer);
        }
Пример #15
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));
     }
 }
        public void Write(CallRequest <T> value, IMsgPackWriter writer)
        {
            writer.WriteMapHeader(2);

            _keyConverter.Write(Key.FunctionName, writer);
            _stringConverter.Write(value.FunctionName, writer);

            _keyConverter.Write(Key.Tuple, writer);
            _tupleConverter.Write(value.Tuple, writer);
        }
        public void Write(EvalRequest <T> value, IMsgPackWriter writer)
        {
            writer.WriteMapHeader(2);

            _keyConverter.Write(Key.Expression, writer);
            _stringConverter.Write(value.Expression, writer);

            _keyConverter.Write(Key.Tuple, writer);
            _tupleConverter.Write(value.Tuple, writer);
        }
        public void Write(TarantoolTuple value, IMsgPackWriter writer)
        {
            if (value == null)
            {
                _nullConverter.Write(null, writer);
                return;
            }

            writer.WriteArrayHeader(0);
        }
Пример #19
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);
        }
Пример #20
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);
        }
Пример #21
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);
        }
Пример #22
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);
        }
Пример #23
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));
 }
Пример #24
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);
        }
Пример #25
0
 public void Write(T?value, IMsgPackWriter writer)
 {
     if (value.HasValue)
     {
         _converter.Write(value.Value, writer);
     }
     else
     {
         _context.NullConverter.Write(null, writer);
     }
 }
Пример #26
0
        private static bool TryWriteUnsignedFixNum(ulong value, IMsgPackWriter writer)
        {
            // positive fixnum
            if (value < 128L)
            {
                writer.Write(unchecked ((byte)value));
                return(true);
            }

            return(false);
        }
 private void WriteImageInfoBody(IImageInfo value, IMsgPackWriter writer)
 {
     _stringConverter.Value.Write("Width", writer);
     _intConverter.Value.Write(value.Width, writer);
     _stringConverter.Value.Write("Height", writer);
     _intConverter.Value.Write(value.Height, writer);
     _stringConverter.Value.Write("Link", writer);
     _stringConverter.Value.Write(value.Link, writer);
     _stringConverter.Value.Write("Credits", writer);
     _stringConverter.Value.Write(value.Credits, writer);
 }
Пример #28
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);
        }
 private void WriteImplementation(IImageInfo value, IMsgPackWriter writer)
 {
     if (value == null)
     {
         writer.Write(DataTypes.Null);
     }
     else
     {
         writer.WriteMapHeader(4U);
         WriteImageInfoBody(value, writer);
     }
 }
Пример #30
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);
        }