Documentation
¶
Overview ¶
Package zwc implements the encoding/decoding of files in the ZWC format
Index ¶
- Constants
- Variables
- func CRC2(message byte) byte
- func DecodeHeader(src []byte) (version, encodingType, checksumType int, err error)
- func DecodeHeaderFromReader(r io.Reader) (version, encodingType, checksumType int, err error)
- func GuessEncodingType(p []byte) int
- func NewCatDecoder(r io.Reader) io.Reader
- func NewCustomDecoder(enc *Encoding, r io.Reader) io.Reader
- func NewDecoder(r io.Reader) io.Reader
- func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser
- func ValidEncoding(version, encodingType, checksumType int) (err error)
- type CorruptHeaderError
- type CorruptPayloadError
- type Encoding
- func (enc *Encoding) Checksum() uint64
- func (enc *Encoding) ChecksumType() int
- func (enc *Encoding) Decode(dst, src []byte) (n, m int, err error)
- func (enc *Encoding) DecodeChecksum(p []byte) (checksum uint64, m int, err error)
- func (enc *Encoding) DecodePayload(dst, src []byte) (n, m int, err error)
- func (enc *Encoding) DecodedPayloadMaxLen(n int) int
- func (enc *Encoding) DelimCharAsUTF8() []byte
- func (enc *Encoding) Encode(dst, src []byte) int
- func (enc *Encoding) EncodeChecksum(dst []byte) int
- func (enc *Encoding) EncodeHeader(dst []byte) int
- func (enc *Encoding) EncodePayload(dst, src []byte) int
- func (enc *Encoding) EncodedChecksumMaxLen() int
- func (enc *Encoding) EncodedHeaderLen() int
- func (enc *Encoding) EncodedMaxLen(n int) int
- func (enc *Encoding) EncodedPayloadMaxLen(n int) int
- func (enc *Encoding) EncodingType() int
- func (enc *Encoding) Version() int
- type InvalidEncodingError
Constants ¶
const ( V1DelimChar = '\u034F' V1DelimCharUTF8 = "\xcd\x8f" )
Variables ¶
var ( CRC8 = &crc.Parameters{ Width: 8, Polynomial: 0x07, Init: 0x00, ReflectIn: false, ReflectOut: false, FinalXor: 0x00, } CRC16 = &crc.Parameters{ Width: 16, Polynomial: 0x1021, Init: 0x0000, ReflectIn: false, ReflectOut: false, FinalXor: 0x0000, } CRC32 = &crc.Parameters{ Width: 32, Polynomial: 0x04C11DB7, Init: 0xFFFFFFFF, ReflectIn: true, ReflectOut: true, FinalXor: 0xFFFFFFFF, } )
Functions ¶
func DecodeHeader ¶
DecodeHeader takes an encoded header with or without any delim chars and returns the encoding settings for the payload and checksum. These can then be passed to NewEncoding to create an Encoding.
func DecodeHeaderFromReader ¶
func GuessEncodingType ¶
GuessEncodingType uses heuristics to guess the encoding of the payload
func NewCustomDecoder ¶
NewCustomDecoder requires an Encoding, meaning the header must be decoded beforehand. r must contain only the data + delim + checksum
func NewDecoder ¶
NewDecoder creates a decoder which decodes the header from r, therefore it doesn't require an Encoding. It takes the entirety of the encoded data and no preprocessing is need. If you want to override the encoding settings use NewCustomDecoder.
func NewEncoder ¶
func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser
func ValidEncoding ¶
Types ¶
type CorruptHeaderError ¶
type CorruptHeaderError struct { HeaderLength int // length of the decoded header in bits CRCFail bool // crc failed // contains filtered or unexported fields }
func (CorruptHeaderError) Error ¶
func (e CorruptHeaderError) Error() string
type CorruptPayloadError ¶
type CorruptPayloadError struct { NotValidUTF8 bool // payload contains no utf8 characters IncompleteByte bool // decoding resulted in an incomplete byte ShortCRC bool // decoded crc is too short CRCFail bool // checksum doesn't match calculated crc NoDelimChar bool // no delim char between payload and checksum UnexpectedDelimChar bool // delim char after checksum (use NewCatDecoder) // contains filtered or unexported fields }
func (CorruptPayloadError) Error ¶
func (e CorruptPayloadError) Error() string
type Encoding ¶
type Encoding struct {
// contains filtered or unexported fields
}
func NewCustomEncoding ¶
func NewEncoding ¶
func (*Encoding) ChecksumType ¶
func (*Encoding) Decode ¶
Decode decodes the data + delim + checksum in src and writes it to dst. This function can only be used after decoding the header with DecodeHeader and creating an Encoding. n is the number of bytes written to dst and m is the number of bytes read from src.
func (*Encoding) DecodeChecksum ¶
DecodeChecksum decodes the checksum in p and returns the checksum. If the checksum is decoded successfully and the checksum matches, err is nil. m is the number of bytes read from p.
func (*Encoding) DecodePayload ¶
DecodePayload decodes the payload in src and writes it to dst. n is the number of bytes written to dst and m is the number of bytes read from src.
func (*Encoding) DecodedPayloadMaxLen ¶
DecodedPayloadMaxLen returns the maximum length of the decoded payload where n is the length of the encoded payload
func (*Encoding) DelimCharAsUTF8 ¶
DelimCharAsUTF8 is a convenience function which returns the delimChar as a UTF8 encoded slice of bytes
func (*Encoding) EncodeChecksum ¶
func (*Encoding) EncodeHeader ¶
func (*Encoding) EncodePayload ¶
func (*Encoding) EncodedChecksumMaxLen ¶
EncodedChecksumLen returns the maximum length in bytes of the encoded ZWC checksum
func (*Encoding) EncodedHeaderLen ¶
EncodedHeaderLen returns the length in bytes of the encoded ZWC header
func (*Encoding) EncodedMaxLen ¶
EncodedLen returns the maximum length in bytes of the encoded ZWC file
func (*Encoding) EncodedPayloadMaxLen ¶
EncodedPayloadLen returns the maximum length in bytes of the encoded ZWC payload
func (*Encoding) EncodingType ¶
type InvalidEncodingError ¶
type InvalidEncodingError struct { InvalidVersion bool InvalidEncodingType bool InvalidChecksumType bool // contains filtered or unexported fields }
func (InvalidEncodingError) Error ¶
func (e InvalidEncodingError) Error() string