// Copyright 2024 Matthew Rich . All rights reserved. package containerlog import ( "fmt" "errors" "encoding/binary" ) type StreamType byte const ( StreamStdin StreamType = 0x0 StreamStdout StreamType = 0x1 StreamStderr StreamType = 0x2 ) var ( ErrInvalidStreamType error = errors.New("Invalid container log stream type") ) func (s StreamType) Validate() error { switch s { case StreamStdin, StreamStdout, StreamStderr: return nil } return fmt.Errorf("%w: %d", ErrInvalidStreamType, s) } func (s StreamType) Log(msg string) (log []byte) { msgLen := len(msg) log = make([]byte, 8 + msgLen) binary.BigEndian.PutUint64(log, uint64(msgLen)) log[0] = byte(s) copy(log[8:], []byte(msg)) return }