Пример #1
0
 public static void AddFooStruct(FlatBufferBuilder builder, Offset<NamespaceA.NamespaceB.StructInNestedNS> fooStructOffset)
 {
     builder.AddStruct(2, fooStructOffset.Value, 0);
 }
Пример #2
0
 public static void AddPos(FlatBufferBuilder builder, int posOffset)
 {
     builder.AddStruct(0, posOffset, 0);
 }
Пример #3
0
 public static void AddObject(FlatBufferBuilder builder, int objectOffset)
 {
     builder.AddStruct(0, objectOffset, 0);
 }
Пример #4
0
        private int SerializePropertyValue(object obj, FieldTypeDefinition field)
        {
            var typeModel = field.TypeModel;

            if (typeModel.IsReferenceType && obj == null)
            {
                if (field.Required)
                {
                    throw new FlatBuffersSerializationException("Required field '{0}' is not set", field.Name);
                }
            }

            if (field.DefaultValueProvider.IsDefaultValue(obj))
            {
                return(_builder.Offset);
            }

            switch (typeModel.BaseType)
            {
            case BaseType.Bool:
            {
                _builder.AddBool(field.Index, (bool)obj, false);
                break;
            }

            case BaseType.Char:
            {
                _builder.AddSbyte(field.Index, (sbyte)obj, 0);
                break;
            }

            case BaseType.UType:
            case BaseType.UChar:
            {
                _builder.AddByte(field.Index, (byte)obj, 0);
                break;
            }

            case BaseType.Short:
            {
                _builder.AddShort(field.Index, (short)obj, 0);
                break;
            }

            case BaseType.UShort:
            {
                _builder.AddUshort(field.Index, (ushort)obj, 0);
                break;
            }

            case BaseType.Int:
            {
                _builder.AddInt(field.Index, (int)obj, 0);
                break;
            }

            case BaseType.UInt:
            {
                _builder.AddUint(field.Index, (uint)obj, 0);
                break;
            }

            case BaseType.Long:
            {
                _builder.AddLong(field.Index, (long)obj, 0);
                break;
            }

            case BaseType.ULong:
            {
                _builder.AddUlong(field.Index, (ulong)obj, 0);
                break;
            }

            case BaseType.Float:
            {
                _builder.AddFloat(field.Index, (float)obj, 0);
                break;
            }

            case BaseType.Double:
            {
                _builder.AddDouble(field.Index, (double)obj, 0);
                break;
            }

            case BaseType.Struct:
            {
                if (typeModel.IsStruct)
                {
                    // Structs are serialized inline
                    var structOffset = SerializeStruct(obj, typeModel);
                    _builder.AddStruct(field.Index, structOffset, 0);
                }
                else
                {
                    // Is a table, so grab the offset
                    AddReferenceFieldOffset(obj, field);
                }

                break;
            }

            case BaseType.String:
            case BaseType.Vector:
            case BaseType.Union:
            {
                AddReferenceFieldOffset(obj, field);
                break;
            }

            default:
            {
                throw new InvalidOperationException();
            }
            }
            return(_builder.Offset);
        }