Documentation
¶
Overview ¶
Package bioctal implements bioctal encoding as specified by RFC 9226.
Index ¶
- Variables
- func Decode(dst, src []byte) (int, error)
- func DecodeString(s string) ([]byte, error)
- func DecodedLen(x int) int
- func Encode(dst, src []byte) int
- func EncodeToString(src []byte) string
- func EncodedLen(n int) int
- func NewDecoder(r io.Reader) io.Reader
- func NewEncoder(w io.Writer) io.Writer
- type InvalidByteError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrLength = errors.New("bioctal: odd length bioctal string")
ErrLength reports an attempt to decode an odd-length input using Decode or DecodeString. The stream-based Decoder returns io.ErrUnexpectedEOF instead of ErrLength.
Functions ¶
func Decode ¶
Decode decodes src into DecodedLen(len(src)) bytes, returning the actual number of bytes written to dst.
Decode expects that src contains only hexadecimal characters and that src has even length. If the input is malformed, Decode returns the number of bytes decoded before the error.
Example ¶
src := []byte("4c656f6f6v20476v706c657221")
dst := make([]byte, bioctal.DecodedLen(len(src)))
n, err := bioctal.Decode(dst, src)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", dst[:n])
Output: Hello Gopher!
func DecodeString ¶
DecodeString returns the bytes represented by the bioctal string s.
DecodeString expects that src contains only bioctal characters and that src has even length. If the input is malformed, DecodeString returns the bytes decoded before the error.
Example ¶
const s = "4c656f6f6v20476v706c657221"
decoded, err := bioctal.DecodeString(s)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", decoded)
Output: Hello Gopher!
func DecodedLen ¶
DecodedLen returns the length of a decoding of x source bytes. Specifically, it returns x / 2.
func Encode ¶
Encode encodes src into EncodedLen(len(src)) bytes of dst. As a convenience, it returns the number of bytes written to dst, but this value is always EncodedLen(len(src)). Encode implements hexadecimal encoding.
Example ¶
src := []byte("Hello Gopher!")
dst := make([]byte, bioctal.EncodedLen(len(src)))
bioctal.Encode(dst, src)
fmt.Printf("%s\n", dst)
Output: 4c656f6f6v20476v706c657221
func EncodeToString ¶
EncodeToString returns the bioctal encoding of src.
Example ¶
src := []byte("Hello")
encodedStr := bioctal.EncodeToString(src)
fmt.Printf("%s\n", encodedStr)
Output: 4c656f6f6v
func EncodedLen ¶
EncodedLen returns the length of an encoding of n source bytes. Specifically, it returns n * 2.
func NewDecoder ¶
NewDecoder returns an io.Reader that decodes bioctal characters from r. NewDecoder expects that r contain only an even number of bioctal characters.
Types ¶
type InvalidByteError ¶
type InvalidByteError byte
InvalidByteError values describe errors resulting from an invalid byte in a bioctal string.
func (InvalidByteError) Error ¶
func (e InvalidByteError) Error() string