public FlatBuffersType(BaseType baseType = BaseType.None, StructDef structDef = null, EnumDef enumDef = null)
 {
     BaseType    = baseType;
     ElementType = BaseType.None;
     StructDef   = structDef;
     EnumDef     = enumDef;
 }
예제 #2
0
        public int ParseFieldDecl(int offset, string schemaStr, StructDef structDef)
        {
            offset = SkipWhitespace(offset, schemaStr);
            string identifier;

            offset = ParseIdentifier(offset, schemaStr, out identifier);
            offset = SkipWhitespace(offset, schemaStr);
            offset = Consume(":", offset, schemaStr);
            offset = SkipWhitespace(offset, schemaStr);
            FlatBuffersType type;
            string          constantValue = null;

            offset = ParseType(offset, schemaStr, out type);
            offset = SkipWhitespace(offset, schemaStr);
            if (schemaStr[offset] == '=')
            {
                offset = ParseConstant(offset, schemaStr, out constantValue);
                offset = SkipWhitespace(offset, schemaStr);
            }

            /* TODO?? these are the "attributes" but correspond to "metadata" grammar rule
             * if (schemaStr[offset] != ';') {
             *  offset = ParseMetaData(offset, schemaStr);
             * }*/
            offset = Consume(";", offset, schemaStr);
            structDef.AddField(identifier, type, constantValue);
            return(offset);
        }
예제 #3
0
 private FlatBufferWrapper(StructDef structDef, int bb_pos, ByteBuffer bb, bool forceDefaults)
 {
     this.bb_pos    = bb_pos;
     this.bb        = bb;
     StructDef      = structDef;
     _forceDefaults = forceDefaults;
 }
예제 #4
0
 public FlatBufferWrapper(StructDef structDef, ByteBuffer bb, bool forceDefaults = false)
     : this(
         structDef,
         bb.GetInt(bb.Position) + bb.Position,
         bb,
         forceDefaults)
 {
 }
예제 #5
0
        public int CreateStruct(StructDef structDef, object[] args)
        {
            Builder.Prep(structDef.MinAlign, structDef.ByteSize);
            for (var i = structDef.Fields.Count - 1; i >= 0; i--)
            {
                var fieldDef = structDef.Fields.Symbols[i];
                switch (fieldDef.Value.type.BaseType)
                {
                case BaseType.Bool:
                    Builder.PutByte((bool)args[i] ? (byte)1 : (byte)0);
                    break;

                case BaseType.Byte:
                    Builder.PutSbyte((sbyte)args[i]);
                    break;

                case BaseType.UByte:
                    Builder.PutByte((byte)args[i]);
                    break;

                case BaseType.Short:
                    Builder.PutShort((short)args[i]);
                    break;

                case BaseType.UShort:
                    Builder.PutUshort((ushort)args[i]);
                    break;

                case BaseType.Int:
                    Builder.PutInt((int)args[i]);
                    break;

                case BaseType.UInt:
                    Builder.PutUint((uint)args[i]);
                    break;

                case BaseType.Long:
                    Builder.PutLong((long)args[i]);
                    break;

                case BaseType.ULong:
                    Builder.PutUlong((ulong)args[i]);
                    break;

                case BaseType.Float:
                    Builder.PutFloat((float)args[i]);
                    break;

                case BaseType.Double:
                    Builder.PutDouble((double)args[i]);
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            return(Builder.Offset);
        }
예제 #6
0
 public int ParseTypeDecl(int offset, string schemaStr, StructDef structDef)
 {
     offset = SkipWhitespace(offset, schemaStr);
     // TODO?? offset = ParseMetaData(offset, schemaStr, structDef);
     offset = Consume("{", offset, schemaStr);
     offset = ParseFieldDeclPlus(offset, schemaStr, structDef);
     offset = Consume("}", offset, schemaStr);
     return(offset);
 }
예제 #7
0
        public FieldDef GetFieldDef(string fieldName, StructDef structDef = null)
        {
            var fieldDef = (structDef ?? CurrentStructDef).Fields.Lookup(fieldName);

            if (fieldName == null)
            {
                throw new ArgumentException($"FieldName {fieldName} not found.", nameof(fieldName));
            }
            return(fieldDef);
        }
예제 #8
0
        public StructDef LookupOrCreateStruct(string name)
        {
            var def = Structs.Lookup(name);

            if (def == null)
            {
                def = new StructDef {
                    Name        = name,
                    Predecl     = true,
                    TypeBuilder = this,
                };
                Structs.Add(name, def);
            }
            return(def);
        }
예제 #9
0
        public int ParseFieldDeclPlus(int offset, string schemaStr, StructDef structDef)
        {
            offset = ParseFieldDecl(offset, schemaStr, structDef);
            var finished = false;

            while (offset < schemaStr.Length && !finished)
            {
                offset = SkipWhitespace(offset, schemaStr);
                if (schemaStr[offset] == '}')
                {
                    finished = true;
                }
                else
                {
                    offset = ParseFieldDecl(offset, schemaStr, structDef);
                }
            }
            return(offset);
        }
예제 #10
0
 public void AddVector(string fieldName, int posOffset, StructDef structDef = null)
 {
     AddPreallocatedField(fieldName, posOffset, 0, structDef);
 }
예제 #11
0
        public void AddPreallocatedField(string fieldName, int posOffset, int voffset, StructDef structDef = null)
        {
            var fieldDef = CurrentStructDef.Fields.Lookup(fieldName);
            var fieldIdx = CurrentStructDef.Fields.LookupIdx(fieldName);

            if (fieldDef.Value.type.IsStruct && fieldDef.Value.type.StructDef.Fixed)
            {
                Builder.AddStruct(fieldIdx, posOffset, voffset);
            }
            else
            {
                Builder.AddOffset(fieldIdx, posOffset, voffset);
            }
        }