Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetBuilder ¶
func GetBuilder() *flatbuffers.Builder
func PutBuilder ¶
func PutBuilder(b *flatbuffers.Builder)
Types ¶
type Buffer ¶
func (*Buffer) UnsafeBytes ¶
UnsafeBytes returns a slice of bytes that will automatically add the Buffer it came from back into the pool when the GC attempts to collect it. This is only useful when the returned byte slice needs to 'outlive' the buffer, but an allocation isn't preferable. For example:
func Marshal(v interface{}) ([]byte, error) { b := pools.GetBuffer() defer pools.PutBuffer() err := json.NewEncoder(b).Encode() return b.Bytes(), err } func MyHandler(w http.ResponseWriter, r *http.Request) { b, err := Marshal("hello, world!") if err != nil { http.Error(w, err.String(), http.StatusInternalServerError) return } // The Buffer created in the 'Marshal' call has already been put back // into the pool. Any other goroutine can now collect it from the pool. // New writes to the Buffer will overwrite 'b' since 'b' points directly // to the Buffer's internal buffer. This can corrupt data and race // conditions in Go are undefined behavior. _, err := w.Write(b) if err != nil { ... } }
By calling UnsafeBytes instead, the data would be protected.
IMPORTANT: Do not call pools.PutBuffer on the Buffer if you call UnsafeBytes at all. Additionally, do not append to the returned slice. Reallocation will invalidate the Buffer.
func (*Buffer) WriteGroups ¶
WriteGroups writes the interval [offset, offset+groupLen) to w N times. Each number is prefixed with '$' and suffixed with ', '. The final value in an interval and final interval in a set are not suffixed with ', '. The intervals are wrapped in parenthases. An error is only returned if the arguments are invalid. Arguments are invalid if offset < 0 or groups == 0.
WriteInterval(0, 4, 2) // ($0, $1, $2, $3, $4), ($5, $6, $7, $8, $9)
func (*Buffer) WriteInt64 ¶
WriteInt64 is a wrapper that writes i to w.
func (*Buffer) WriteInterval ¶
WriteInterval writes the interval [start, end] to w N times. Each number is prefixed with '$' and suffixed with ', '. The final value in an interval and final interval in a set are not suffixed with ', '. The intervals are wrapped in parenthases. An error is only returned if the arguments are invalid. Arguments are invalid if start < 0, start >= end, or num == 0.
WriteInterval(0, 4, 2) // (0, 1, 2, 3, 4), (0, 1, 2, 3, 4)