journal/attr.go

33 lines
810 B
Go

package journal
// Attr represents a key/value pair ("attribute"), several of which comprise a
// journal entry.
type Attr struct {
Key AttrKey
Value []byte
}
// UseTextProto returns true if we can use the text protocol to encode the
// message on the wire. It is heuristic; it will only consider messages of
// ≤ 128 bytes. Following guidance at https://systemd.io/JOURNAL_NATIVE_PROTOCOL/
// it is intended to make for nice strace(1) traces.
func (a Attr) UseTextProto() bool {
if len(a.Value) > 128 {
return false
}
for _, b := range a.Value {
if b < 32 || b > 0xFE {
return false
}
}
return true
}
// StringAttr captures the common paradigm of building an Attr from a string.
func StringAttr(key AttrKey, value string) Attr {
return Attr{
Key: key,
Value: []byte(value),
}
}