Documentation
¶
Overview ¶
Package gsm7 provides conversions to and from 7bit packed user data.
Index ¶
- Variables
- func Decode(src []byte, options ...DecoderOption) ([]byte, error)
- func Encode(src []byte, options ...EncoderOption) ([]byte, error)
- func Pack7Bit(u []byte, fillBits int) []byte
- func Pack7BitUSSD(u []byte, fillBits int) []byte
- func Unpack7Bit(p []byte, fillBits int) []byte
- func Unpack7BitUSSD(p []byte, fillBits int) []byte
- type CharsetOption
- type Decoder
- type DecoderOption
- type Encoder
- type EncoderOption
- type ErrInvalidSeptet
- type ErrInvalidUTF8
- type ExtCharsetOption
- type NullDecoder
- type StrictOption
Constants ¶
This section is empty.
Variables ¶
var ( // Strict specifies that the decoder should return an error rather than // ignoring undecodable septets. Strict = StrictOption{} // WithoutExtCharset specifies that no extension character set will be // available to decode escaped characters. WithoutExtCharset = NullDecoder{} )
Functions ¶
func Decode ¶ added in v0.2.0
func Decode(src []byte, options ...DecoderOption) ([]byte, error)
Decode converts the src from unpacked GSM7 to UTF-8.
func Encode ¶ added in v0.2.0
func Encode(src []byte, options ...EncoderOption) ([]byte, error)
Encode converts the src from UTF-8 to GSM7 and writes the result to dst.
The return value includes the encoded GSM7 bytes, and any error that occurred during encoding.
func Pack7Bit ¶
Pack7Bit packs an array of septets into an 8bit array as per the packing rules defined in 3GPP TS 23.038 Section 6.1.2.1
The padBits is the number of bits of pad to place at the beginning of the packed array, as the packed septets may not start on an octet boundary. Packed arrays containing 8n or 8n-1 digits both return 8n septets. The caller must be aware of the number of expected digits in order to distinguish between a 0 septet ending the sequence in the 8n case, and 0 padding in the 8n-1 case.
func Pack7BitUSSD ¶
Pack7BitUSSD packs an array of septets into an 8bit array as per the packing rules defined in 3GPP TS 23.038 Section 6.1.2.3
The padBits is the number of bits of pad to place at the beginning of the packed array, as the packed septets may not start on an octet boundary. A filler CR is added to the final octet if there are 7 bits unused (to distinguish from the 0x00 septet), or if the last septet is CR and ends on an octet boundary (so it wont be considered filler).
func Unpack7Bit ¶
Unpack7Bit unpacks septets, packed into an 8bit array as per the packing rules defined in 3GPP TS 23.038 Section 6.1.2.1, into an array of septets.
The fillBits is the number of bits of pad at the beginning of the src, as the packed septets may not start on an octet boundary.
func Unpack7BitUSSD ¶
Unpack7BitUSSD unpacks septets, packed into an 8bit array, as per the packing rules defined in 3GPP TS 23.038 Section 6.1.2.3, into an array of septets.
The fillBits is the number of bits of pad at the beginning of the src, as the packed septets may not start on an octet boundary. Any trailing CR is assumed to be filler if it ends an octet boundary, or if it starts on an octet boundary and the previous character is also CR.
Types ¶
type CharsetOption ¶ added in v0.2.0
type CharsetOption struct {
// contains filtered or unexported fields
}
CharsetOption specifies the character set to be used for encoding and decoding.
func WithCharset ¶ added in v0.2.0
func WithCharset(nli int) CharsetOption
WithCharset specifies the character set map used for encoding or decoding.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder converts from GSM7 to UTF-8 using a particular character set.
func NewDecoder ¶
func NewDecoder(options ...DecoderOption) Decoder
NewDecoder returns a new GSM7 decoder which uses the default character set.
func (Decoder) Strict ¶
Strict makes the Decoder return an error if an unknown character is detected when looking up a septet in the character set (not the extension set).
func (Decoder) WithCharset ¶
WithCharset replaces the character set map used by the Decoder.
type DecoderOption ¶ added in v0.2.0
type DecoderOption interface {
// contains filtered or unexported methods
}
DecoderOption applies an option to a Decoder.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder converts from UTF-8 to GSM7 using a particular character set.
func NewEncoder ¶
func NewEncoder(options ...EncoderOption) Encoder
NewEncoder returns a new GSM7 encoder which uses the default character set.
func (*Encoder) Encode ¶
Encode converts the src from UTF-8 to GSM7 and writes the result to dst.
The return value includes the encoded GSM7 bytes, and any error that occurred during encoding.
func (Encoder) WithCharset ¶
WithCharset replaces the character set map used by the Encoder.
type EncoderOption ¶ added in v0.2.0
type EncoderOption interface {
// contains filtered or unexported methods
}
EncoderOption applies an option to an Encoder.
type ErrInvalidSeptet ¶
type ErrInvalidSeptet byte
ErrInvalidSeptet indicates a septet cannot be decoded.
func (ErrInvalidSeptet) Error ¶
func (e ErrInvalidSeptet) Error() string
type ErrInvalidUTF8 ¶
type ErrInvalidUTF8 rune
ErrInvalidUTF8 indicates a rune cannot be converted to GSM7.
func (ErrInvalidUTF8) Error ¶
func (e ErrInvalidUTF8) Error() string
type ExtCharsetOption ¶ added in v0.2.0
type ExtCharsetOption struct {
// contains filtered or unexported fields
}
ExtCharsetOption specifies the extension character set to be used for encoding and decoding.
func WithExtCharset ¶ added in v0.2.0
func WithExtCharset(nli int) ExtCharsetOption
WithExtCharset replaces the extension character set map used for encoding or decoding.
type NullDecoder ¶ added in v0.2.0
type NullDecoder struct{}
NullDecoder fails to decode any characters.
type StrictOption ¶ added in v0.2.0
type StrictOption struct{}
StrictOption specifies that the decoder should return an error rather than ignoring undecodable septets.