Documentation
¶
Index ¶
- func BytesToStr(b []byte) string
- func BytesToValue(codec acodec.Codec, data []byte, v interface{}) error
- func Recover()
- func Safe(call func())
- func StrToBytes(s string) []byte
- func ValueToBytes(codec acodec.Codec, v interface{}) []byte
- func ValueToBytesOwned(codec acodec.Codec, v interface{}) (data []byte, owned bool)
- type Empty
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToStr ¶
BytesToStr converts b to string without copying. b must not be modified while the result is in use.
func BytesToValue ¶ added in v1.2.15
BytesToValue decodes data into v, which should be a pointer. *[]byte gets a copy of data, *string gets string(data), *error gets errors.New(string(data)), and other types are decoded by codec, or acodec.DefaultCodec if codec is nil. It does nothing if v is nil.
func Recover ¶
func Recover()
Recover recovers from a panic and logs it with the stack trace. It must be called directly by defer.
func StrToBytes ¶
StrToBytes converts s to []byte without copying. The result must not be modified.
func ValueToBytes ¶
ValueToBytes converts v to []byte: []byte and string (or pointers to them) and error are used as-is without copying, other values are encoded by codec, or acodec.DefaultCodec if codec is nil. It returns nil if v is nil or the encoding fails.
func ValueToBytesOwned ¶ added in v1.2.18
ValueToBytesOwned is like ValueToBytes, and also reports whether the result is safe to keep after the call returns (e.g. queued for an async send) without copying.
owned is false only for []byte and *[]byte inputs, whose content the caller may still modify; callers that keep such a slice must copy it. Strings, errors and codec output cannot be modified by the caller, so owned is true.