1package nlenc
2
3import "bytes"
4
5// Bytes returns a null-terminated byte slice with the contents of s.
6func Bytes(s string) []byte {
7	return append([]byte(s), 0x00)
8}
9
10// String returns a string with the contents of b from a null-terminated
11// byte slice.
12func String(b []byte) string {
13	// If the string has more than one NULL terminator byte, we want to remove
14	// all of them before returning the string to the caller; hence the use of
15	// strings.TrimRight instead of strings.TrimSuffix (which previously only
16	// removed a single NULL).
17	return string(bytes.TrimRight(b, "\x00"))
18}
19