Skip to content

Instantly share code, notes, and snippets.

@lux
Created June 12, 2019 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lux/af8ca8ebe333c27106b00e13328e7c8e to your computer and use it in GitHub Desktop.
Save lux/af8ca8ebe333c27106b00e13328e7c8e to your computer and use it in GitHub Desktop.
// <auto-generated>
// automatically generated by the FlatBuffers compiler, do not modify
// </auto-generated>
namespace Data
{
using global::System;
using global::FlatBuffers;
public struct Instruction : IFlatbufferObject
{
private Table __p;
public ByteBuffer ByteBuffer { get { return __p.bb; } }
public static Instruction GetRootAsInstruction(ByteBuffer _bb) { return GetRootAsInstruction(_bb, new Instruction()); }
public static Instruction GetRootAsInstruction(ByteBuffer _bb, Instruction obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
public void __init(int _i, ByteBuffer _bb) { __p.bb_pos = _i; __p.bb = _bb; }
public Instruction __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
public string UserId { get { int o = __p.__offset(4); return o != 0 ? __p.__string(o + __p.bb_pos) : null; } }
#if ENABLE_SPAN_T
public Span<byte> GetUserIdBytes() { return __p.__vector_as_span(4); }
#else
public ArraySegment<byte>? GetUserIdBytes() { return __p.__vector_as_arraysegment(4); }
#endif
public byte[] GetUserIdArray() { return __p.__vector_as_array<byte>(4); }
public Types.InstructionType Code { get { int o = __p.__offset(6); return o != 0 ? (Types.InstructionType)__p.bb.GetSbyte(o + __p.bb_pos) : Types.InstructionType.Start; } }
public Instructions InstructionsType { get { int o = __p.__offset(8); return o != 0 ? (Instructions)__p.bb.Get(o + __p.bb_pos) : Instructions.NONE; } }
public TTable? Instructions<TTable>() where TTable : struct, IFlatbufferObject { int o = __p.__offset(10); return o != 0 ? (TTable?)__p.__union<TTable>(o) : null; }
public string Extra { get { int o = __p.__offset(12); return o != 0 ? __p.__string(o + __p.bb_pos) : null; } }
#if ENABLE_SPAN_T
public Span<byte> GetExtraBytes() { return __p.__vector_as_span(12); }
#else
public ArraySegment<byte>? GetExtraBytes() { return __p.__vector_as_arraysegment(12); }
#endif
public byte[] GetExtraArray() { return __p.__vector_as_array<byte>(12); }
public static Offset<Instruction> CreateInstruction(FlatBufferBuilder builder,
StringOffset userIdOffset = default(StringOffset),
Types.InstructionType code = Types.InstructionType.Start,
Instructions instructions_type = Instructions.NONE,
int instructionsOffset = 0,
StringOffset extraOffset = default(StringOffset)) {
builder.StartObject(5);
Instruction.AddExtra(builder, extraOffset);
Instruction.AddInstructions(builder, instructionsOffset);
Instruction.AddUserId(builder, userIdOffset);
Instruction.AddInstructionsType(builder, instructions_type);
Instruction.AddCode(builder, code);
return Instruction.EndInstruction(builder);
}
public static void StartInstruction(FlatBufferBuilder builder) { builder.StartObject(5); }
public static void AddUserId(FlatBufferBuilder builder, StringOffset userIdOffset) { builder.AddOffset(0, userIdOffset.Value, 0); }
public static void AddCode(FlatBufferBuilder builder, Types.InstructionType code) { builder.AddSbyte(1, (sbyte)code, 0); }
public static void AddInstructionsType(FlatBufferBuilder builder, Instructions instructionsType) { builder.AddByte(2, (byte)instructionsType, 0); }
public static void AddInstructions(FlatBufferBuilder builder, int instructionsOffset) { builder.AddOffset(3, instructionsOffset, 0); }
public static void AddExtra(FlatBufferBuilder builder, StringOffset extraOffset) { builder.AddOffset(4, extraOffset.Value, 0); }
public static Offset<Instruction> EndInstruction(FlatBufferBuilder builder) {
int o = builder.EndObject();
return new Offset<Instruction>(o);
}
};
}
// <auto-generated>
// automatically generated by the FlatBuffers compiler, do not modify
// </auto-generated>
namespace Data
{
public enum Instructions : byte
{
NONE = 0,
SetupData = 1,
SyncData = 2,
TeleportData = 3,
};
}

The generated code results in an error because the generated Instructions() method for line 24 of test.fbs gets confused with the Instructions union in the return type and cast on lines 28, and also on line 41 of Instruction.cs because the namespace is not specified explicitly for tables in the same namespace.

The solution seems to be to always specify the namespace explicitly, so line 28 goes from:

  public Instructions InstructionsType { get { int o = __p.__offset(8); return o != 0 ? (Instructions)__p.bb.Get(o + __p.bb_pos) : Instructions.NONE; } }

To this:

  public Data.Instructions InstructionsType { get { int o = __p.__offset(8); return o != 0 ? (Data.Instructions)__p.bb.Get(o + __p.bb_pos) : Data.Instructions.NONE; } }
namespace Types;
enum InstructionType:byte {
Start = 0,
Stop = 1,
Reset = 2,
Seek = 3,
Setup = 4,
Resync = 5,
Teleport = 6
}
namespace Data;
union Instructions {
SetupData,
SyncData,
TeleportData
}
table Instruction {
userId:string;
code:Types.InstructionType;
instructions:Instructions; // The generated Instructions() method will get confused with the Instructions union
extra:string;
}
table SetupData {
}
table SyncData {
}
table TeleportData {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment