Ejemplo n.º 1
0
        // generic reader: reads the next TypeInfo object from stream and returns it
        /// <exception cref="System.IO.IOException"/>
        private FieldTypeInfo GenericReadTypeInfo(RecordInput rin, string tag)
        {
            string fieldName = rin.ReadString(tag);
            TypeID id        = GenericReadTypeID(rin, tag);

            return(new FieldTypeInfo(fieldName, id));
        }
Ejemplo n.º 2
0
        /// <summary>Two base typeIDs are equal if they refer to the same type</summary>
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null)
            {
                return(false);
            }
            if (this.GetType() != o.GetType())
            {
                return(false);
            }
            TypeID oTypeID = (TypeID)o;

            return(this.typeVal == oTypeID.typeVal);
        }
Ejemplo n.º 3
0
        // generic reader: reads the next TypeID object from stream and returns it
        /// <exception cref="System.IO.IOException"/>
        private TypeID GenericReadTypeID(RecordInput rin, string tag)
        {
            byte typeVal = rin.ReadByte(tag);

            switch (typeVal)
            {
            case TypeID.RIOType.Bool:
            {
                return(TypeID.BoolTypeID);
            }

            case TypeID.RIOType.Buffer:
            {
                return(TypeID.BufferTypeID);
            }

            case TypeID.RIOType.Byte:
            {
                return(TypeID.ByteTypeID);
            }

            case TypeID.RIOType.Double:
            {
                return(TypeID.DoubleTypeID);
            }

            case TypeID.RIOType.Float:
            {
                return(TypeID.FloatTypeID);
            }

            case TypeID.RIOType.Int:
            {
                return(TypeID.IntTypeID);
            }

            case TypeID.RIOType.Long:
            {
                return(TypeID.LongTypeID);
            }

            case TypeID.RIOType.Map:
            {
                TypeID tIDKey   = GenericReadTypeID(rin, tag);
                TypeID tIDValue = GenericReadTypeID(rin, tag);
                return(new MapTypeID(tIDKey, tIDValue));
            }

            case TypeID.RIOType.String:
            {
                return(TypeID.StringTypeID);
            }

            case TypeID.RIOType.Struct:
            {
                Org.Apache.Hadoop.Record.Meta.StructTypeID stID = new Org.Apache.Hadoop.Record.Meta.StructTypeID
                                                                      ();
                int numElems = rin.ReadInt(tag);
                for (int i = 0; i < numElems; i++)
                {
                    stID.Add(GenericReadTypeInfo(rin, tag));
                }
                return(stID);
            }

            case TypeID.RIOType.Vector:
            {
                TypeID tID = GenericReadTypeID(rin, tag);
                return(new VectorTypeID(tID));
            }

            default:
            {
                // shouldn't be here
                throw new IOException("Unknown type read");
            }
            }
        }
Ejemplo n.º 4
0
 /// <summary>Construct a FiledTypeInfo with the given field name and the type</summary>
 internal FieldTypeInfo(string fieldID, TypeID typeID)
 {
     this.fieldID = fieldID;
     this.typeID  = typeID;
 }
Ejemplo n.º 5
0
        /// <summary>read/skip bytes from stream based on a type</summary>
        /// <exception cref="System.IO.IOException"/>
        public static void Skip(RecordInput rin, string tag, TypeID typeID)
        {
            switch (typeID.typeVal)
            {
            case TypeID.RIOType.Bool:
            {
                rin.ReadBool(tag);
                break;
            }

            case TypeID.RIOType.Buffer:
            {
                rin.ReadBuffer(tag);
                break;
            }

            case TypeID.RIOType.Byte:
            {
                rin.ReadByte(tag);
                break;
            }

            case TypeID.RIOType.Double:
            {
                rin.ReadDouble(tag);
                break;
            }

            case TypeID.RIOType.Float:
            {
                rin.ReadFloat(tag);
                break;
            }

            case TypeID.RIOType.Int:
            {
                rin.ReadInt(tag);
                break;
            }

            case TypeID.RIOType.Long:
            {
                rin.ReadLong(tag);
                break;
            }

            case TypeID.RIOType.Map:
            {
                Index     midx1 = rin.StartMap(tag);
                MapTypeID mtID  = (MapTypeID)typeID;
                for (; !midx1.Done(); midx1.Incr())
                {
                    Skip(rin, tag, mtID.GetKeyTypeID());
                    Skip(rin, tag, mtID.GetValueTypeID());
                }
                rin.EndMap(tag);
                break;
            }

            case TypeID.RIOType.String:
            {
                rin.ReadString(tag);
                break;
            }

            case TypeID.RIOType.Struct:
            {
                rin.StartRecord(tag);
                // read past each field in the struct
                StructTypeID stID = (StructTypeID)typeID;
                IEnumerator <FieldTypeInfo> it = stID.GetFieldTypeInfos().GetEnumerator();
                while (it.HasNext())
                {
                    FieldTypeInfo tInfo = it.Next();
                    Skip(rin, tag, tInfo.GetTypeID());
                }
                rin.EndRecord(tag);
                break;
            }

            case TypeID.RIOType.Vector:
            {
                Index        vidx1 = rin.StartVector(tag);
                VectorTypeID vtID  = (VectorTypeID)typeID;
                for (; !vidx1.Done(); vidx1.Incr())
                {
                    Skip(rin, tag, vtID.GetElementTypeID());
                }
                rin.EndVector(tag);
                break;
            }

            default:
            {
                // shouldn't be here
                throw new IOException("Unknown typeID when skipping bytes");
            }
            }
        }
Ejemplo n.º 6
0
 /// <summary>Add a field.</summary>
 /// <param name="fieldName">Name of the field</param>
 /// <param name="tid">Type ID of the field</param>
 public virtual void AddField(string fieldName, TypeID tid)
 {
     sTid.GetFieldTypeInfos().AddItem(new FieldTypeInfo(fieldName, tid));
 }
Ejemplo n.º 7
0
 public VectorTypeID(TypeID typeIDElement)
     : base(TypeID.RIOType.Vector)
 {
     this.typeIDElement = typeIDElement;
 }
Ejemplo n.º 8
0
 public MapTypeID(TypeID typeIDKey, TypeID typeIDValue)
     : base(TypeID.RIOType.Map)
 {
     this.typeIDKey   = typeIDKey;
     this.typeIDValue = typeIDValue;
 }