Example #1
0
            public void Write(ThriftProtocol oprot)
            {
                oprot.IncrementRecursionDepth();
                try
                {
                    var struc = new TStruct(/*"Log_args"*/);
                    oprot.WriteStructBegin(struc);
                    TField field = new TField();
                    if (Messages != null)
                    {
//						field.Name = "messages";
                        field.Type = TType.List;
                        field.ID   = 1;
                        oprot.WriteFieldBegin(field);
                        {
                            oprot.WriteListBegin(new TList(TType.Struct, Messages.Count));
                            foreach (LogEntry logEntry in Messages)
                            {
                                // logEntry.Write(oprot);
                                LogEntrySerializer.Write(oprot, logEntry);
                            }
                            oprot.WriteListEnd();
                        }
                        oprot.WriteFieldEnd();
                    }
                    oprot.WriteFieldStop();
                    oprot.WriteStructEnd();
                }
                finally
                {
                    oprot.DecrementRecursionDepth();
                }
            }
Example #2
0
            public void Write(ThriftProtocol oprot)
            {
                oprot.IncrementRecursionDepth();
                try
                {
                    var struc = new TStruct(/*"Log_result"*/);
                    oprot.WriteStructBegin(struc);
                    var field = new TField();

                    if (this.Success != null)
                    {
//						field.Name = "Success";
                        field.Type = TType.I32;
                        field.ID   = 0;
                        oprot.WriteFieldBegin(field);
                        oprot.WriteI32((int)Success.Value);
                        oprot.WriteFieldEnd();
                    }
                    oprot.WriteFieldStop();
                    oprot.WriteStructEnd();
                }
                finally
                {
                    oprot.DecrementRecursionDepth();
                }
            }
        public void Write(ThriftProtocol oprot)
        {
            TStruct struc = new TStruct(/*"TApplicationException"*/);
            TField  field = new TField();

            oprot.WriteStructBegin(struc);

            if (!string.IsNullOrEmpty(Message))
            {
//				field.Name = "message";
                field.Type = TType.String;
                field.ID   = 1;
                oprot.WriteFieldBegin(field);
                oprot.WriteString(Message);
                oprot.WriteFieldEnd();
            }

//			field.Name = "type";
            field.Type = TType.I32;
            field.ID   = 2;
            oprot.WriteFieldBegin(field);
            oprot.WriteI32((int)type);
            oprot.WriteFieldEnd();

            oprot.WriteFieldStop();
            oprot.WriteStructEnd();
        }
Example #4
0
        public override void WriteSpan(Span span, Stream stream)
        {
            var protocol = new ThriftProtocol(new TStreamTransport(stream));

            SpanSerializer.Write(span, protocol);

            protocol.Flush();
        }
        public static TApplicationException Read(ThriftProtocol iprot)
        {
            TField field;

            string        message = null;
            ExceptionType type    = ExceptionType.Unknown;

            iprot.ReadStructBegin();
            while (true)
            {
                field = iprot.ReadFieldBegin();
                if (field.Type == TType.Stop)
                {
                    break;
                }

                switch (field.ID)
                {
                case 1:
                    if (field.Type == TType.String)
                    {
                        message = iprot.ReadString();
                    }
                    else
                    {
                        iprot.Skip(field.Type);
                    }
                    break;

                case 2:
                    if (field.Type == TType.I32)
                    {
                        type = (ExceptionType)iprot.ReadI32();
                    }
                    else
                    {
                        iprot.Skip(field.Type);
                    }
                    break;

                default:
                    iprot.Skip(field.Type);
                    break;
                }

                iprot.ReadFieldEnd();
            }

            iprot.ReadStructEnd();

            return(new TApplicationException(type, message));
        }
Example #6
0
            public void Read(ThriftProtocol iprot)
            {
                iprot.IncrementRecursionDepth();
                try
                {
                    TField field;
                    iprot.ReadStructBegin();
                    while (true)
                    {
                        field = iprot.ReadFieldBegin();
                        if (field.Type == TType.Stop)
                        {
                            break;
                        }
                        switch (field.ID)
                        {
                        case 1:
                            if (field.Type == TType.List)
                            {
                                {
                                    Messages = new List <LogEntry>();
                                    TList list = iprot.ReadListBegin();
                                    for (int i = 0; i < list.Count; ++i)
                                    {
                                        var entry = LogEntrySerializer.Read(iprot);
                                        Messages.Add(entry);
                                    }
                                    iprot.ReadListEnd();
                                }
                            }
                            else
                            {
                                iprot.Skip(field.Type);
                            }
                            break;

                        default:
                            iprot.Skip(field.Type);
                            break;
                        }
                        iprot.ReadFieldEnd();
                    }
                    iprot.ReadStructEnd();
                }
                finally
                {
                    iprot.DecrementRecursionDepth();
                }
            }
Example #7
0
        public static void Write(Endpoint endpoint, ThriftProtocol oprot)
        {
            oprot.IncrementRecursionDepth();
            try
            {
                TStruct struc = new TStruct(/*"Endpoint"*/);
                oprot.WriteStructBegin(struc);
                TField field = new TField();
                if (endpoint.IPAddress != null)
                {
//					field.Name = "ipv4";
                    field.Type = TType.I32;
                    field.ID   = 1;
                    oprot.WriteFieldBegin(field);
                    // oprot.WriteI32(endpoint.IPAddress.);

                    var address = endpoint.IPAddress.GetAddressBytes();
                    oprot.WriteI32(BitConverter.ToInt32(address, 0));

                    oprot.WriteFieldEnd();
                }
                if (endpoint.Port.HasValue)
                {
//					field.Name = "port";
                    field.Type = TType.I16;
                    field.ID   = 2;
                    oprot.WriteFieldBegin(field);
                    oprot.WriteI16((short)endpoint.Port.Value);
                    oprot.WriteFieldEnd();
                }
                if (endpoint.ServiceName != null)
                {
//					field.Name = "service_name";
                    field.Type = TType.String;
                    field.ID   = 3;
                    oprot.WriteFieldBegin(field);
                    oprot.WriteString(endpoint.ServiceName);
                    oprot.WriteFieldEnd();
                }
                oprot.WriteFieldStop();
                oprot.WriteStructEnd();
            }
            finally
            {
                oprot.DecrementRecursionDepth();
            }
        }
        public static void Write(Annotation annotation, ThriftProtocol oprot)
        {
            oprot.IncrementRecursionDepth();
            try
            {
                TStruct struc = new TStruct(/*"Annotation"*/);
                oprot.WriteStructBegin(struc);
                TField field = new TField();
                // if (annotation.Timestamp != DateTimeOffset.MinValue)
                {
//					field.Name = "timestamp";
                    field.Type = TType.I64;
                    field.ID   = 1;
                    oprot.WriteFieldBegin(field);
                    oprot.WriteI64(annotation.Timestamp.ToNixTimeMicro());
                    oprot.WriteFieldEnd();
                }
                if (annotation.Value != null)
                {
//					field.Name = "value";
                    field.Type = TType.String;
                    field.ID   = 2;
                    oprot.WriteFieldBegin(field);
                    oprot.WriteString(annotation.Value);
                    oprot.WriteFieldEnd();
                }
                if (annotation.Host != null)
                {
//					field.Name = "host";
                    field.Type = TType.Struct;
                    field.ID   = 3;
                    oprot.WriteFieldBegin(field);
                    // annotation.Host.Write(oprot);
                    EndpointSerializer.Write(annotation.Host, oprot);
                    oprot.WriteFieldEnd();
                }
                oprot.WriteFieldStop();
                oprot.WriteStructEnd();
            }
            finally
            {
                oprot.DecrementRecursionDepth();
            }
        }
Example #9
0
        public static IList <Span> ReadList(ThriftProtocol iprot)
        {
            iprot.IncrementRecursionDepth();
            var list = new List <Span>();

            try
            {
                var listInfo = iprot.ReadListBegin();
                for (int i = 0; i < listInfo.Count; i++)
                {
                    list.Add(SpanSerializer.Read(iprot));
                }
                iprot.ReadListEnd();
            }
            finally
            {
                iprot.DecrementRecursionDepth();
            }
            return(list);
        }
Example #10
0
            public void Read(ThriftProtocol iprot)
            {
                iprot.IncrementRecursionDepth();
                try
                {
                    TField field;
                    iprot.ReadStructBegin();
                    while (true)
                    {
                        field = iprot.ReadFieldBegin();
                        if (field.Type == TType.Stop)
                        {
                            break;
                        }
                        switch (field.ID)
                        {
                        case 0:
                            if (field.Type == TType.I32)
                            {
                                Success = (ResultCode)iprot.ReadI32();
                            }
                            else
                            {
                                iprot.Skip(field.Type);
                            }
                            break;

                        default:
                            iprot.Skip(field.Type);
                            break;
                        }
                        iprot.ReadFieldEnd();
                    }
                    iprot.ReadStructEnd();
                }
                finally
                {
                    iprot.DecrementRecursionDepth();
                }
            }
Example #11
0
        public static void WriteList(IList <Span> spans, ThriftProtocol oprot)
        {
            oprot.IncrementRecursionDepth();
            try
            {
                var count = spans.Count;
                oprot.WriteListBegin(new TList {
                    Count = count, ElementType = TType.Struct
                });

                for (int i = 0; i < count; i++)
                {
                    Write(spans[i], oprot);
                }

                oprot.WriteListEnd();
            }
            finally
            {
                oprot.DecrementRecursionDepth();
            }
        }
Example #12
0
        public static void Write(BinaryAnnotation annotation, ThriftProtocol oprot)
        {
            oprot.IncrementRecursionDepth();
            try
            {
                var struc = new TStruct(/*"BinaryAnnotation"*/);
                oprot.WriteStructBegin(struc);
                var field = new TField();
                if (annotation.Key != null)
                {
//					field.Name = "key";
                    field.Type = TType.String;
                    field.ID   = 1;
                    oprot.WriteFieldBegin(field);
                    oprot.WriteString(annotation.Key);
                    oprot.WriteFieldEnd();
                }
                // if (annotation.Value != null)
                {
//					field.Name = "value";
                    field.Type = TType.String;
                    field.ID   = 2;
                    oprot.WriteFieldBegin(field);

                    switch (annotation.AnnotationType)
                    {
                    case AnnotationType.BOOL:
                        oprot.WriteI32(1);
                        oprot.WriteByte((sbyte)(annotation.ValAsBool ? 1 : 0));
                        break;

                    case AnnotationType.I16:
                        oprot.WriteI32(2);
                        oprot.WriteI16(annotation.ValAsI16);
                        break;

                    case AnnotationType.I32:
                        oprot.WriteI32(4);
                        oprot.WriteI32(annotation.ValAsI32);
                        break;

                    case AnnotationType.I64:
                        oprot.WriteI32(8);
                        oprot.WriteI64(annotation.ValAsI64);
                        break;

                    case AnnotationType.DOUBLE:
                        oprot.WriteI32(8);
                        oprot.WriteDouble(annotation.ValAsDouble);
                        break;

                    case AnnotationType.BYTES:
                        oprot.WriteBinary(annotation.ValAsBArray, 0, annotation.ValAsBArray.Length);
                        break;

                    case AnnotationType.STRING:
                        oprot.WriteString(annotation.ValAsString);
                        break;
                    }

                    // oprot.WriteBinary(annotation.Value);
                    oprot.WriteFieldEnd();
                }
                // if (annotation.AnnotationType != null)
                {
//					field.Name = "annotation_type";
                    field.Type = TType.I32;
                    field.ID   = 3;
                    oprot.WriteFieldBegin(field);
                    oprot.WriteI32((int)annotation.AnnotationType);
                    oprot.WriteFieldEnd();
                }
                if (annotation.Host != null)
                {
//					field.Name = "host";
                    field.Type = TType.Struct;
                    field.ID   = 4;
                    oprot.WriteFieldBegin(field);
                    EndpointSerializer.Write(annotation.Host, oprot);
                    //annotation.Host.Write(oprot);
                    oprot.WriteFieldEnd();
                }
                oprot.WriteFieldStop();
                oprot.WriteStructEnd();
            }
            finally
            {
                oprot.DecrementRecursionDepth();
            }
        }
Example #13
0
        public static Span Read(ThriftProtocol iprot)
        {
            iprot.IncrementRecursionDepth();
            var span = new Span();

            try
            {
                TField field;
                iprot.ReadStructBegin();
                while (true)
                {
                    field = iprot.ReadFieldBegin();
                    if (field.Type == TType.Stop)
                    {
                        break;
                    }
                    switch (field.ID)
                    {
                    case 1:
                        if (field.Type == TType.I64)
                        {
                            span.TraceId = iprot.ReadI64();
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 3:
                        if (field.Type == TType.String)
                        {
                            span.Name = iprot.ReadString();
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 4:
                        if (field.Type == TType.I64)
                        {
                            span.Id = iprot.ReadI64();
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 5:
                        if (field.Type == TType.I64)
                        {
                            span.ParentId = iprot.ReadI64();
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 6:
                        if (field.Type == TType.List)
                        {
                            {
                                span.Annotations = new List <Annotation>();
                                var _list0 = iprot.ReadListBegin();
                                for (int _i1 = 0; _i1 < _list0.Count; ++_i1)
                                {
                                    var annotation = AnnotationSerializer.Read(iprot);
                                    span.Annotations.Add(annotation);
                                }
                                iprot.ReadListEnd();
                            }
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 8:
                        if (field.Type == TType.List)
                        {
                            {
                                span.BinaryAnnotations = new List <BinaryAnnotation>();
                                var _list3 = iprot.ReadListBegin();
                                for (int _i4 = 0; _i4 < _list3.Count; ++_i4)
                                {
//										BinaryAnnotation _elem5;
//										_elem5 = new BinaryAnnotation();
//										_elem5.Read(iprot);
//										Binary_annotations.Add(_elem5);
                                    var annotation = BinaryAnnotationSerializer.Read(iprot);
                                    span.BinaryAnnotations.Add(annotation);
                                }
                                iprot.ReadListEnd();
                            }
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 9:
                        if (field.Type == TType.Bool)
                        {
                            span.IsDebug = iprot.ReadBool();
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 10:
                        if (field.Type == TType.I64)
                        {
                            span.Timestamp = DateTimeOffsetExtensions.FromLong(iprot.ReadI64());
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 11:
                        if (field.Type == TType.I64)
                        {
                            span.DurationInMicroseconds = iprot.ReadI64();
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    default:
                        iprot.Skip(field.Type);
                        break;
                    }
                    iprot.ReadFieldEnd();
                }
                iprot.ReadStructEnd();
            }
            finally
            {
                iprot.DecrementRecursionDepth();
            }
            return(span);
        }
Example #14
0
        public static void Write(Span span, ThriftProtocol oprot)
        {
            oprot.IncrementRecursionDepth();
            try
            {
                var struc = new TStruct(/*"Span"*/);
                oprot.WriteStructBegin(struc);
                var field = new TField();
                if (span.TraceId != 0L)
                {
//					field.Name = "trace_id";
                    field.Type = TType.I64;
                    field.ID   = 1;
                    oprot.WriteFieldBegin(field);
                    oprot.WriteI64(span.TraceId);
                    oprot.WriteFieldEnd();
                }
                if (span.Name != null)
                {
//					field.Name = "name";
                    field.Type = TType.String;
                    field.ID   = 3;
                    oprot.WriteFieldBegin(field);
                    oprot.WriteString(span.Name);
                    oprot.WriteFieldEnd();
                }
                if (span.Id != 0)
                {
//					field.Name = "id";
                    field.Type = TType.I64;
                    field.ID   = 4;
                    oprot.WriteFieldBegin(field);
                    oprot.WriteI64(span.Id);
                    oprot.WriteFieldEnd();
                }
                if (span.ParentId.HasValue)
                {
//					field.Name = "parent_id";
                    field.Type = TType.I64;
                    field.ID   = 5;
                    oprot.WriteFieldBegin(field);
                    oprot.WriteI64(span.ParentId.Value);
                    oprot.WriteFieldEnd();
                }
                if (span.Annotations != null && span.Annotations.Count != 0)
                {
//					field.Name = "annotations";
                    field.Type = TType.List;
                    field.ID   = 6;
                    oprot.WriteFieldBegin(field);
                    {
                        oprot.WriteListBegin(new TList(TType.Struct, span.Annotations.Count));
                        foreach (var annotation in span.Annotations)
                        {
                            AnnotationSerializer.Write(annotation, oprot);
                        }
                        oprot.WriteListEnd();
                    }
                    oprot.WriteFieldEnd();
                }
                if (span.BinaryAnnotations != null && span.BinaryAnnotations.Count != 0)
                {
//					field.Name = "binary_annotations";
                    field.Type = TType.List;
                    field.ID   = 8;
                    oprot.WriteFieldBegin(field);
                    {
                        oprot.WriteListBegin(new TList(TType.Struct, span.BinaryAnnotations.Count));
                        foreach (BinaryAnnotation annotation in span.BinaryAnnotations)
                        {
                            BinaryAnnotationSerializer.Write(annotation, oprot);
                            // _iter7.Write(oprot);
                        }
                        oprot.WriteListEnd();
                    }
                    oprot.WriteFieldEnd();
                }
                if (span.IsDebug)
                {
//					field.Name = "debug";
                    field.Type = TType.Bool;
                    field.ID   = 9;
                    oprot.WriteFieldBegin(field);
                    oprot.WriteBool(span.IsDebug);
                    oprot.WriteFieldEnd();
                }
                if (span.Timestamp != null)
                {
//					field.Name = "timestamp";
                    field.Type = TType.I64;
                    field.ID   = 10;
                    oprot.WriteFieldBegin(field);
                    oprot.WriteI64(span.Timestamp.Value.ToNixTimeMicro());
                    oprot.WriteFieldEnd();
                }
                if (span.DurationInMicroseconds.HasValue)
                {
//					field.Name = "duration";
                    field.Type = TType.I64;
                    field.ID   = 11;
                    oprot.WriteFieldBegin(field);
                    oprot.WriteI64(span.DurationInMicroseconds.Value);
                    oprot.WriteFieldEnd();
                }
                oprot.WriteFieldStop();
                oprot.WriteStructEnd();
            }
            finally
            {
                oprot.DecrementRecursionDepth();
            }
        }
Example #15
0
        public static Endpoint Read(ThriftProtocol iprot)
        {
            var endpoint = new Endpoint();

            iprot.IncrementRecursionDepth();
            try
            {
                iprot.ReadStructBegin();
                while (true)
                {
                    var field = iprot.ReadFieldBegin();
                    if (field.Type == TType.Stop)
                    {
                        break;
                    }
                    switch (field.ID)
                    {
                    case 1:
                        if (field.Type == TType.I32)
                        {
                            endpoint.IPAddress = new IPAddress((long)iprot.ReadI32());
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 2:
                        if (field.Type == TType.I16)
                        {
                            endpoint.Port = (ushort)iprot.ReadI16();
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

                    case 3:
                        if (field.Type == TType.String)
                        {
                            endpoint.ServiceName = iprot.ReadString();
                        }
                        else
                        {
                            iprot.Skip(field.Type);
                        }
                        break;

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

            return(endpoint);
        }
Example #16
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);
        }
Example #17
0
        public override Span ReadSpan(Stream stream)
        {
            var protocol = new ThriftProtocol(new TStreamTransport(stream));

            return(SpanSerializer.Read(protocol));
        }
        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);
        }
Example #19
0
 public ScribeService(ThriftProtocol protocol)
 {
     _protocol = protocol;
 }