コード例 #1
0
ファイル: StringExpression.cs プロジェクト: oliora/bond
        public static Expression Convert(Expression valueAsString, BondDataType type)
        {
            if (type == BondDataType.BT_STRING || type == BondDataType.BT_WSTRING)
            {
                return valueAsString;
            }

            return Expression.Call(methods[type], valueAsString, invariantCulture);
        }
コード例 #2
0
 public void ReadContainerBegin(out int count, out BondDataType keyType, out BondDataType valueType)
 {
     keyType   = (BondDataType)input.ReadUInt8();
     valueType = (BondDataType)input.ReadUInt8();
     count     = (int)input.ReadVarUInt32();
 }
コード例 #3
0
 public void WriteFieldOmitted(BondDataType dataType, ushort id, Metadata metadata)
 {
 }
コード例 #4
0
ファイル: ObjectParser.cs プロジェクト: zsybupt/bond
 public Expression Scalar(Expression valueType, BondDataType expectedType, ValueHandler handler)
 {
     Debug.Assert(expectedType == schemaType.GetBondDataType());
     return(handler(typeAlias.Convert(value, schemaType)));
 }
コード例 #5
0
 public void WriteFieldBegin(BondDataType dataType, ushort id, Metadata metadata)
 {
     writer.WriteStartElement(Prefix, metadata.name, null);
 }
コード例 #6
0
ファイル: SimpleJsonWriter.cs プロジェクト: csdahlberg/bond
 public void WriteFieldOmitted(BondDataType type, ushort id, Metadata metadata)
 {}
コード例 #7
0
        public Expression Container(BondDataType? expectedType, ContainerHandler handler)
        {
            if (schemaType.IsBondNullable())
                return Nullable(handler);

            if (schemaType.IsBondBlob())
                return BlobContainer(handler);

            var itemType = schemaType.GetValueType();

            ContainerItemHandler itemHandler = (item, next, count) => handler(
                new ObjectParser(this, item, itemType),
                Expression.Constant(itemType.GetBondDataType()),
                next,
                count);

            if (value.Type.IsArray)
                return ArrayContainer(itemHandler);

            if (value.Type.IsGenericType())
            {
                if (typeof(IList<>).MakeGenericType(value.Type.GetGenericArguments()[0]).IsAssignableFrom(value.Type))
                    return ListContainer(itemHandler);

                if (typeof(LinkedList<>) == value.Type.GetGenericTypeDefinition())
                    return LinkedListContainer(itemHandler);
            }

            return EnumerableContainer(itemHandler);
        }
コード例 #8
0
ファイル: SimpleXmlWriter.cs プロジェクト: csdahlberg/bond
 public void WriteContainerBegin(int count, BondDataType elementType)
 { }
コード例 #9
0
 static Expression InvalidType(BondDataType expectedType, Expression valueType)
 {
     return(ThrowExpression.InvalidTypeException(Expression.Constant(expectedType), valueType));
 }
コード例 #10
0
ファイル: ProtocolTests.cs プロジェクト: csdahlberg/bond
 public void WriteContainerBegin(int count, BondDataType keyType, BondDataType valueType)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
ファイル: ProtocolTests.cs プロジェクト: csdahlberg/bond
 public void WriteFieldOmitted(BondDataType type, ushort id, Metadata metadata)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
 public void WriteContainerBegin(int count, BondDataType elementType)
 {
     writer.WriteStartArray();
 }
コード例 #13
0
 public void WriteContainerBegin(int count, BondDataType keyType, BondDataType valueType)
 {
     writer.WriteStartArray();
 }
コード例 #14
0
        public void WriteFieldBegin(BondDataType type, ushort id, Metadata metadata)
        {
            string name;

            writer.WritePropertyName(metadata.attributes.TryGetValue(NameAttribute, out name) ? name : metadata.name);
        }
コード例 #15
0
 public void WriteContainerBegin(int count, BondDataType keyType, BondDataType valueType)
 {
     throw new NotImplementedException();
 }
コード例 #16
0
ファイル: TaggedParser.cs プロジェクト: zhipenghan/bond
 public Expression Scalar(Expression valueType, BondDataType expectedType, ValueHandler handler)
 {
     return(MatchOrCompatible(valueType, expectedType,
                              type => handler(reader.Read(type))));
 }
コード例 #17
0
 public abstract Expression Scalar(Expression valueType, BondDataType expectedType, ValueHandler handler);
コード例 #18
0
ファイル: SimpleXmlWriter.cs プロジェクト: csdahlberg/bond
 public void WriteFieldBegin(BondDataType dataType, ushort id, Metadata metadata)
 {
     writer.WriteStartElement(Prefix, metadata.name, null);
 }
コード例 #19
0
ファイル: FlatteningParser.cs プロジェクト: csdahlberg/bond
 public Expression Container(BondDataType? expectedType, ContainerHandler handler)
 {
     throw new System.NotImplementedException();
 }
コード例 #20
0
 public Expression Scalar(Expression valueType, BondDataType expectedType, ValueHandler handler)
 {
     Debug.Assert(expectedType == schemaType.GetBondDataType());
     return handler(typeAlias.Convert(value, schemaType));
 }
コード例 #21
0
ファイル: FlatteningParser.cs プロジェクト: csdahlberg/bond
 public Expression Map(BondDataType? expectedKeyType, BondDataType? expectedValueType, MapHandler handler)
 {
     throw new System.NotImplementedException();
 }
コード例 #22
0
ファイル: SimpleJsonWriter.cs プロジェクト: csdahlberg/bond
 public void WriteContainerBegin(int count, BondDataType elementType)
 {
     writer.WriteStartArray();
 }
コード例 #23
0
ファイル: FlatteningParser.cs プロジェクト: csdahlberg/bond
 public Expression Scalar(Expression valueType, BondDataType expectedType, ValueHandler handler)
 {
     throw new System.NotImplementedException();
 }
コード例 #24
0
ファイル: FastBinary.cs プロジェクト: johndpope/Medusa
 public void ReadContainerBegin(out int count, out BondDataType elementType)
 {
     elementType = (BondDataType)input.ReadUInt8();
     count       = (int)input.ReadVarUInt32();
 }
コード例 #25
0
 static void ThrowInvalidTypeException(BondDataType expectedType, BondDataType actualType)
 {
     throw new InvalidDataException(string.Format("Invalid type {0}, expected {1}", actualType, expectedType));
 }
コード例 #26
0
        public Expression Scalar(Expression valueType, BondDataType expectedType, ValueHandler handler)
        {
            Debug.Assert(valueType is ConstantExpression);

            return(handler(reader.Read((BondDataType)(valueType as ConstantExpression).Value)));
        }
コード例 #27
0
        public void WriteFieldOmitted(BondDataType dataType, ushort id, Metadata metadata)
        {
            // Simple doesn't support omitting fields so instead we write the default value
            Audit.ArgRule(!metadata.default_value.nothing, "Field set to nothing can't be serialized.");

            switch (dataType)
            {
            case BondDataType.BT_BOOL:
                WriteBool(0 != metadata.default_value.uint_value);
                break;

            case BondDataType.BT_UINT8:
                WriteUInt8((byte)metadata.default_value.uint_value);
                break;

            case BondDataType.BT_UINT16:
                WriteUInt16((UInt16)metadata.default_value.uint_value);
                break;

            case BondDataType.BT_UINT32:
                WriteUInt32((UInt32)metadata.default_value.uint_value);
                break;

            case BondDataType.BT_UINT64:
                WriteUInt64(metadata.default_value.uint_value);
                break;

            case BondDataType.BT_FLOAT:
                WriteFloat((float)metadata.default_value.double_value);
                break;

            case BondDataType.BT_DOUBLE:
                WriteDouble(metadata.default_value.double_value);
                break;

            case BondDataType.BT_STRING:
                WriteString(metadata.default_value.string_value);
                break;

            case BondDataType.BT_LIST:
            case BondDataType.BT_SET:
            case BondDataType.BT_MAP:
                WriteContainerBegin(0, dataType);
                break;

            case BondDataType.BT_INT8:
                WriteInt8((sbyte)metadata.default_value.int_value);
                break;

            case BondDataType.BT_INT16:
                WriteInt16((Int16)metadata.default_value.int_value);
                break;

            case BondDataType.BT_INT32:
                WriteInt32((Int32)metadata.default_value.int_value);
                break;

            case BondDataType.BT_INT64:
                WriteInt64(metadata.default_value.int_value);
                break;

            case BondDataType.BT_WSTRING:
                WriteWString(metadata.default_value.wstring_value);
                break;

            default:
                Throw.InvalidBondDataType(dataType);
                break;
            }
        }
コード例 #28
0
 public void WriteContainerBegin(int count, BondDataType keyType, BondDataType valueType)
 {
     output.WriteUInt8((byte)keyType);
     output.WriteUInt8((byte)valueType);
     output.WriteVarUInt32((uint)count);
 }
コード例 #29
0
 public static void InvalidBondDataType(BondDataType type)
 {
     throw new InvalidDataException(string.Format("Invalid BondDataType {0}", type));
 }
コード例 #30
0
 public void WriteFieldOmitted(BondDataType type, ushort id, Metadata metadata)
 {
     throw new NotImplementedException();
 }
コード例 #31
0
 public void WriteFieldBegin(BondDataType dataType, ushort id, Metadata metadata)
 {
 }
コード例 #32
0
        public override Expression Scalar(Expression valueType, BondDataType expectedType, ValueHandler handler)
        {
            JsonToken scalarTokenType;

            if (!ScalarTokenTypes.TryGetValue(expectedType, out scalarTokenType))
            {
                Debug.Assert(false, "Scalar should be called only on scalar expected types.");
            }

            Expression convertedValue;

            if (scalarTokenType == JsonToken.Integer)
            {
                // reader.Value is a boxed long and must be unboxed to the right type in order to
                // avoid an InvalidCastException.
                convertedValue = Expression.Convert(Reader.Value, typeof(long));
            }
            else if (scalarTokenType == JsonToken.Float)
            {
                convertedValue = Expression.Convert(Reader.Value, typeof(double));
            }
            else
            {
                convertedValue = Reader.Value;
            }

            var errorMessage =
                StringExpression.Format(
                    "Invalid input, expected JSON token of type {0}, encountered {1}",
                    Expression.Constant(scalarTokenType, typeof(object)),
                    Expression.Convert(Reader.TokenType, typeof(object)));

            Expression embeddedExpression = handler(convertedValue);

#if SUPPORTS_BIGINTEGER
            if (expectedType == BondDataType.BT_UINT64 && scalarTokenType == JsonToken.Integer)
            {
                embeddedExpression =
                    Expression.IfThenElse(
                        Expression.TypeIs(Reader.Value, typeof(long)),
                        embeddedExpression,
                        handler(Expression.Convert(Reader.Value, typeof(BigInteger))));
            }
#endif

            var handleValue =
                Expression.IfThenElse(
                    JsonTokenEquals(scalarTokenType),
                    embeddedExpression,
                    ThrowUnexpectedInput(errorMessage));

            // If a floating point value is expected also accept an integer
            if (scalarTokenType == JsonToken.Float)
            {
                handleValue = Expression.IfThenElse(
                    JsonTokenEquals(JsonToken.Integer),
                    handler(Expression.Convert(Reader.Value, typeof(long))),
                    handleValue);
            }

            return
                (Expression.Block(
                     handleValue,
                     Reader.Read()));
        }
コード例 #33
0
 public void WriteContainerBegin(int count, BondDataType elementType)
 {
 }
コード例 #34
0
ファイル: TaggedParser.cs プロジェクト: zhipenghan/bond
 // Generate expression to handle exact match or compatible type
 private static Expression MatchOrCompatible(Expression valueType, BondDataType expectedType, TypeHandlerCompiletime handler)
 {
     return(MatchOrElse(valueType, expectedType, handler,
                        TryCompatible(valueType, expectedType, handler)));
 }
コード例 #35
0
 public void WriteContainerBegin(int count, BondDataType keyType, BondDataType valueType)
 {
 }
コード例 #36
0
ファイル: SimpleXmlWriter.cs プロジェクト: csdahlberg/bond
 public void WriteContainerBegin(int count, BondDataType keyType, BondDataType valueType)
 { }
コード例 #37
0
 public void WriteFieldBegin(BondDataType type, ushort id, Metadata metadata)
 {
     if (id <= 5)
     {
         AddBytes(1);
     }
     else if (id <= 0xFF)
     {
         AddBytes(2);
     }
     else
     {
         AddBytes(3);
     }
 }
コード例 #38
0
ファイル: ThrowExpression.cs プロジェクト: csdahlberg/bond
 static void ThrowInvalidTypeException(BondDataType expectedType, BondDataType actualType)
 {
     throw new InvalidDataException(string.Format("Invalid type {0}, expected {1}", actualType, expectedType));
 }
コード例 #39
0
 public void WriteContainerBegin(int count, BondDataType elementType)
 {
     if (count < 7)
     {
         AddBytes(1);
     }
     else
     {
         AddBytes(1);
         AddVarUInt32((uint)count);
     }
 }
コード例 #40
0
        public Expression Map(BondDataType? expectedKeyType, BondDataType? expectedValueType, MapHandler handler)
        {
            Debug.Assert(schemaType.IsBondMap());

            var itemType = schemaType.GetKeyValueType();
            return EnumerableContainer((item, next, count) => handler(
                new ObjectParser(this, Expression.Property(item, "Key"), itemType.Key),
                new ObjectParser(this, Expression.Property(item, "Value"), itemType.Value),
                Expression.Constant(itemType.Key.GetBondDataType()),
                Expression.Constant(itemType.Value.GetBondDataType()),
                next,
                Expression.Empty(),
                count));
        }
コード例 #41
0
 public void WriteContainerBegin(int count, BondDataType keyType, BondDataType valueType)
 {
     AddBytes(2);
     AddVarUInt32((uint)count);
 }
コード例 #42
0
ファイル: SimpleJsonWriter.cs プロジェクト: csdahlberg/bond
 public void WriteFieldBegin(BondDataType type, ushort id, Metadata metadata)
 {
     string name;
     writer.WritePropertyName(metadata.attributes.TryGetValue(NameAttribute, out name) ? name : metadata.name);
 }
コード例 #43
0
 public Expression WriteFieldOmitted(BondDataType type, ushort id, Metadata metadata)
 {
     return(Expression.Call(writer, fieldOmitted, Expression.Constant(type), Expression.Constant(id), Expression.Constant(metadata)));
 }
コード例 #44
0
ファイル: SimpleJsonWriter.cs プロジェクト: csdahlberg/bond
 public void WriteContainerBegin(int count, BondDataType keyType, BondDataType valueType)
 {
     writer.WriteStartArray();
 }
コード例 #45
0
ファイル: FastBinary.cs プロジェクト: johndpope/Medusa
 public void WriteFieldBegin(BondDataType type, ushort id, Metadata metadata)
 {
     output.WriteUInt8((byte)type);
     output.WriteUInt16(id);
 }
コード例 #46
0
ファイル: FastBinary.cs プロジェクト: johndpope/Medusa
 public void WriteContainerBegin(int count, BondDataType elementType)
 {
     output.WriteUInt8((byte)elementType);
     output.WriteVarUInt32((uint)count);
 }
コード例 #47
0
 public void WriteContainerBegin(int count, BondDataType keyType, BondDataType valueType)
 {
     AddBytes(2);
     AddVarUInt32((uint)count);
 }