return nil
}
-// Decode binary data from buf into data according to the given byte order.
-//
-// Returns an error if buf is too small, otherwise the number of
+// Decode decodes binary data from buf into data according to
+// the given byte order.
+// It returns an error if buf is too small, otherwise the number of
// bytes consumed from buf.
func Decode(buf []byte, order ByteOrder, data any) (int, error) {
if n, _ := intDataSize(data); n != 0 {
return err
}
-// Encode the binary representation of data into buf according to the given byte order.
-//
-// Returns an error if the buffer is too short, otherwise the number of bytes
-// written into buf.
+// Encode encodes the binary representation of data into buf according to
+// the given byte order.
+// It returns an error if buf is too small, otherwise the number of
+// bytes written into buf.
func Encode(buf []byte, order ByteOrder, data any) (int, error) {
// Fast path for basic types and slices.
if n, _ := intDataSize(data); n != 0 {
return size, nil
}
-// Append the binary representation of data to buf.
-//
+// Append appends the binary representation of data to buf.
// buf may be nil, in which case a new buffer will be allocated.
// See [Write] on which data are acceptable.
-//
-// Returns the (possibily extended) buffer containing data or an error.
+// It returns the (possibily extended) buffer containing data or an error.
func Append(buf []byte, order ByteOrder, data any) ([]byte, error) {
// Fast path for basic types and slices.
if n, _ := intDataSize(data); n != 0 {