Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
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();
            }
        }