Ejemplo n.º 1
0
 public override void WriteFieldBegin(Field field)
 {
     WriteJSONInteger(field.ID);
     WriteJSONObjectStart();
     WriteJSONString(GetTypeNameForTypeID(field.Type));
 }
Ejemplo n.º 2
0
 public override void WriteFieldBegin(Field field)
 {
     WriteByte((byte)field.Type);
     WriteI16(field.ID);
     WriteString(field.Name ?? "");
     WriteString(field.ClassName ?? "");
 }
Ejemplo n.º 3
0
 public override Field ReadFieldBegin()
 {
     Field field = new Field();
     byte ch = reader.Peek();
     if (ch == RBRACE[0])
     {
         field.Type = DataType.Stop;
     }
     else
     {
         field.ID = (short)ReadJSONInteger();
         ReadJSONObjectStart();
         field.Type = GetTypeIDForTypeName(ReadJSONString(false));
     }
     return field;
 }
Ejemplo n.º 4
0
        public override Field ReadFieldBegin()
        {
            Field field = new Field();
            field.Type = (DataType)ReadByte();

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

            }

            return field;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
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 == DataType.Bool)
     {
         // we want to possibly include the value, so we'll wait.
         booleanField_ = field;
     }
     else
     {
         WriteFieldBeginInternal(field, 0xFF);
     }
 }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
0
 public abstract void WriteFieldBegin(Field field);