package hex import ( "encoding/hex" "smesh.lol/pkg/lol/errorf" ) var Enc = hex.EncodeToString var EncBytes = hex.Encode var Dec = hex.DecodeString var DecBytes = hex.Decode var DecLen = hex.DecodedLen type InvalidByteError = hex.InvalidByteError // EncAppend encodes src as hex and appends to dst. func EncAppend(dst, src []byte) []byte { l := len(dst) dst = append(dst, []byte{:len(src)*2}...) hex.Encode(dst[l:], src) return dst } // DecAppend decodes hex src and appends to dst. func DecAppend(dst, src []byte) ([]byte, error) { if len(src) < 2 { return dst, errorf.E([]byte("nothing to decode")) } if dst == nil { dst = []byte{} } l := len(dst) dst = append(dst, []byte{:len(src)/2}...) _, err := hex.Decode(dst[l:], src) return dst, err }