builder := flatbuffers.NewBuilder(0) nameOffset := builder.CreateString("Alice") age := 25 PersonStart(builder) PersonAddName(builder, nameOffset) PersonAddAge(builder, age) personOffset := PersonEnd(builder) builder.Finish(personOffset)
builder := flatbuffers.NewBuilder(0) numbers := []uint32{1, 2, 3} VectorStart(builder, len(numbers)) for i := len(numbers) - 1; i >= 0; i-- { builder.PrependUint32(numbers[i]) } vectorOffset := builder.EndVector(len(numbers)) builder.Finish(vectorOffset)This example demonstrates how to use the Builder to create a FlatBuffer object representing an array of integers. The `NewBuilder` function is used to create a new instance of the Builder. The `VectorStart` function is used to start building the vector object, specifying the length of the array as its argument. The `PrependUint32` function is used to add the integer values to the vector. Finally, the `EndVector` method is used to finish building the vector object and return the offset to the buffer containing the serialized object.