Beispiel #1
0
 public override void WriteFieldBegin(Field field)
 {
     WriteByte((byte)field.Type);
     WriteI16(field.ID);
     WriteString(field.Name ?? "");
     WriteString(field.ClassName ?? "");
 }
Beispiel #2
0
        public void Write(Serializer oprot)
        {
            Struct struc = new Struct("TApplicationException");
            Field field = new Field();

            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();
        }
Beispiel #3
0
        public override Field ReadFieldBegin()
        {
            Field field = new Field();
            field.Type = (TType)ReadByte();

            if (field.Type != TType.Stop)
            {
                field.ID = ReadI16();
                field.Name = ReadString();
                field.ClassName = ReadString();

            }

            return field;
        }
Beispiel #4
0
 /**
  * Write a field header containing the field id and field type. If the
  * difference between the current field id and the last one is small (< 15),
  * then the field id will be encoded in the 4 MSB as a delta. Otherwise, the
  * field id will follow the type header as a zigzag varint.
  */
 public override void WriteFieldBegin(Field field)
 {
     if (field.Type == TType.Bool)
     {
         // we want to possibly include the value, so we'll wait.
         booleanField_ = field;
     }
     else
     {
         WriteFieldBeginInternal(field, 0xFF);
     }
 }
Beispiel #5
0
        /**
         * The workhorse of WriteFieldBegin. It has the option of doing a
         * 'type override' of the type header. This is used specifically in the
         * boolean field case.
         */
        private void WriteFieldBeginInternal(Field field, byte typeOverride)
        {
            // short lastField = lastField_.Pop();

            // if there's a type override, use that.
            byte typeToWrite = typeOverride == 0xFF ? getCompactType(field.Type) : typeOverride;

            // check if we can use delta encoding for the field id
            if (field.ID > lastFieldId_ && field.ID - lastFieldId_ <= 15)
            {
                // Write them together
                WriteByteDirect((field.ID - lastFieldId_) << 4 | typeToWrite);
            }
            else
            {
                // Write them separate
                WriteByteDirect(typeToWrite);
                WriteI16(field.ID);
            }

            lastFieldId_ = field.ID;
            // lastField_.push(field.id);
        }
Beispiel #6
0
        /**
         * Read a field header off the wire.
         */
        public override Field ReadFieldBegin()
        {
            byte type = ReadByte();

            // if it's a stop, then we can return immediately, as the struct is over.
            if (type == Types.STOP)
            {
                return TSTOP;
            }

            short fieldId;

            // mask off the 4 MSB of the type header. it could contain a field id delta.
            short modifier = (short)((type & 0xf0) >> 4);
            if (modifier == 0)
            {
                // not a delta. look ahead for the zigzag varint field id.
                fieldId = ReadI16();
            }
            else
            {
                // has a delta. add the delta to the last Read field id.
                fieldId = (short)(lastFieldId_ + modifier);
            }

            Field field = new Field("", getTType((byte)(type & 0x0f)), fieldId);

            // if this happens to be a boolean field, the value is encoded in the type
            if (isBoolType(type))
            {
                // save the boolean value in a special instance variable.
                boolValue_ = (byte)(type & 0x0f) == Types.BOOLEAN_TRUE ? true : false;
            }

            // push the new field onto the field stack so we can keep the deltas going.
            lastFieldId_ = field.ID;
            return field;
        }
Beispiel #7
0
 public override void WriteFieldBegin(Field field)
 {
     WriteJSONInteger(field.ID);
     WriteJSONObjectStart();
     WriteJSONString(GetTypeNameForTypeID(field.Type));
 }
Beispiel #8
0
 public override Field ReadFieldBegin()
 {
     Field field = new Field();
     byte ch = reader.Peek();
     if (ch == RBRACE[0])
     {
         field.Type = TType.Stop;
     }
     else
     {
         field.ID = (short)ReadJSONInteger();
         ReadJSONObjectStart();
         field.Type = GetTypeIDForTypeName(ReadJSONString(false));
     }
     return field;
 }
Beispiel #9
0
 public override void WriteFieldBegin(Field field)
 {
     WriteByte((byte)field.Type);
     WriteI16(field.ID);
 }
Beispiel #10
0
 public abstract void WriteFieldBegin(Field field);