Marshal() currently returns the whole bytes buffer which makes it awkward to use correctly.
If you want write a k/v pair you have resort to error-prone hacks like:
val, _ := sb.Marshal(msg)
sp := sb.Len()
key := sb.PutUint64(123).Bytes()[sp:]
A better API is probably something like making all methods return a Result:
type Result struct {
*Buf
Err error
Dat []byte
}
This way chaining works and you can easily extract the data written by the last operation.
Marshal()currently returns the whole bytes buffer which makes it awkward to use correctly.If you want write a k/v pair you have resort to error-prone hacks like:
A better API is probably something like making all methods return a
Result:This way chaining works and you can easily extract the data written by the last operation.