Initial release.
This commit is contained in:
brent saner
2024-07-09 23:40:20 -04:00
parent 7ce62f8107
commit d4bb259b83
27 changed files with 4673 additions and 12 deletions

80
funcs_fieldvalue.go Normal file
View File

@@ -0,0 +1,80 @@
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
}