go_wireproto/funcs_fieldvalue.go
brent saner d4bb259b83
v1.0.0
Initial release.
2024-07-10 00:18:54 -04:00

81 lines
1.3 KiB
Go

package wireproto
/*
MarshalBinary renders a FieldValue into a byte-packed format.
Unlike other types (aside from FieldName), it does *not* include its allocator!
*/
func (f *FieldValue) MarshalBinary() (data []byte, err error) {
if f == nil {
data = []byte{}
return
}
data = []byte(*f)
return
}
// MarshalText renders a FieldValue into plaintext.
func (f *FieldValue) MarshalText() (data []byte, err error) {
if f == nil {
data = []byte{}
return
}
data = []byte(*f)
return
}
// UnmarshalBinary populates a FieldValue from packed bytes.
func (f *FieldValue) UnmarshalBinary(data []byte) (err error) {
if data == nil || len(data) == 0 {
return
}
// Strip the header; remainder should be value.
*f = FieldValue(data)
return
}
// UnmarshalText populates a FieldValue from plaintext.
func (f *FieldValue) UnmarshalText(data []byte) (err error) {
if data == nil || len(data) == 0 {
return
}
*f = FieldValue(data)
return
}
// Size returns the FieldValue's calculated size (in bytes).
func (f *FieldValue) Size() (size int) {
if f == nil {
return
}
size = len(*f)
return
}
// String returns a string representation of a FieldValue.
func (f *FieldValue) String() (s string) {
if f == nil {
return
}
s = string([]byte(*f))
return
}