コード例 #1
0
        public static BinaryAnnotation Read(ThriftProtocol iprot)
        {
            iprot.IncrementRecursionDepth();
            var annotation = new BinaryAnnotation();

            byte[] value = null;
            try
            {
                iprot.ReadStructBegin();
                while (true)
                {
                    var field = iprot.ReadFieldBegin();
                    if (field.Type == TType.Stop)
                    {
                        break;
                    }
                    switch (field.ID)
                    {
                    case 1:
                        if (field.Type == TType.String)
                        {
                            annotation.Key = iprot.ReadString();
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 2:
                        if (field.Type == TType.String)
                        {
                            value = iprot.ReadBinary();
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 3:
                        if (field.Type == TType.I32)
                        {
                            annotation.AnnotationType = (AnnotationType)iprot.ReadI32();
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 4:
                        if (field.Type == TType.Struct)
                        {
                            // Host = new Endpoint();
                            // Host.Read(iprot);
                            annotation.Host = EndpointSerializer.Read(iprot);
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    default:
                        iprot.Skip(field.Type);
                        break;
                    }
                    iprot.ReadFieldEnd();
                }
                iprot.ReadStructEnd();
            }
            finally
            {
                iprot.DecrementRecursionDepth();
            }
            // annotation.InitWith(value);

            if (value != null)
            {
                switch (annotation.AnnotationType)
                {
                case AnnotationType.BOOL:
                    annotation.ValAsBool = value.Length == 1 && value[0] == 1;
                    break;

                case AnnotationType.I16:
                    Array.Reverse(value);
                    annotation.ValAsI16 = BitConverter.ToInt16(value, 0);
                    break;

                case AnnotationType.I32:
                    Array.Reverse(value);
                    annotation.ValAsI32 = BitConverter.ToInt32(value, 0);
                    break;

                case AnnotationType.I64:
                    Array.Reverse(value);
                    annotation.ValAsI64 = BitConverter.ToInt64(value, 0);
                    break;

                case AnnotationType.DOUBLE:
                    Array.Reverse(value);
                    annotation.ValAsDouble = BitConverter.ToDouble(value, 0);
                    break;

                case AnnotationType.BYTES:
                    Array.Reverse(value);
                    annotation.ValAsBArray = value;
                    break;

                case AnnotationType.STRING:
                    annotation.ValAsString = Encoding.UTF8.GetString(value, 0, value.Length);
                    break;
                }
            }

            return(annotation);
        }
コード例 #2
0
        public static Annotation Read(ThriftProtocol iprot)
        {
            iprot.IncrementRecursionDepth();
            var annotation = new Annotation();

            try
            {
                iprot.ReadStructBegin();
                while (true)
                {
                    var field = iprot.ReadFieldBegin();
                    if (field.Type == TType.Stop)
                    {
                        break;
                    }
                    switch (field.ID)
                    {
                    case 1:
                        if (field.Type == TType.I64)
                        {
                            annotation.Timestamp = DateTimeOffsetExtensions.FromLong(iprot.ReadI64());
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 2:
                        if (field.Type == TType.String)
                        {
                            annotation.Value = iprot.ReadString();
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 3:
                        if (field.Type == TType.Struct)
                        {
//								Host = new Endpoint();
//								Host.Read(iprot);
                            annotation.Host = EndpointSerializer.Read(iprot);
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    default:
                        iprot.Skip(field.Type);
                        break;
                    }
                    iprot.ReadFieldEnd();
                }
                iprot.ReadStructEnd();
            }
            finally
            {
                iprot.DecrementRecursionDepth();
            }
            return(annotation);
        }