import flatbuffers
# Generated by `flatc`.
import Buffer.String

builder = flatbuffers.Builder(0)

message = builder.CreateString('Hello World!')

Buffer.String.StringStart(builder)
Buffer.String.StringAddMessage(builder,message)
s = Buffer.String.StringEnd(builder)

builder.Finish(s)

# We now have a FlatBuffer that we could store on disk or send over a network.

# ...Saving to file or sending over a network code goes here...

# Instead, we are going to access this buffer right away (as if we just
# received it).

buf = builder.Output()

# Note: We use `0` for the offset here, since we got the data using the
# `builder.Output()` method. This simulates the data you would store/receive
# in your FlatBuffer. If you wanted to read from the `builder.Bytes` directly,
# you would need to pass in the offset of `builder.Head()`, as the builder
# actually constructs the buffer backwards.
s = Buffer.String.String.GetRootAsString(buf, 0)

# Note: We did set the `Value` field explicitly, so we get a value different from default.
assert s.Message() == "Hello World!"
print 'The FlatBuffer was successfully created and verified!'