gsm7

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2020 License: MIT Imports: 2 Imported by: 7

Documentation

Overview

Package gsm7 provides conversions to and from 7bit packed user data.

Index

Constants

This section is empty.

Variables

View Source
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

func Pack7Bit(u []byte, fillBits int) []byte

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

func Pack7BitUSSD(u []byte, fillBits int) []byte

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

func Unpack7Bit(p []byte, fillBits int) []byte

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

func Unpack7BitUSSD(p []byte, fillBits int) []byte

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) Decode

func (d *Decoder) Decode(src []byte) ([]byte, error)

Decode converts the src from unpacked GSM7 to UTF-8.

func (Decoder) Strict

func (d Decoder) Strict() Decoder

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

func (d Decoder) WithCharset(set charset.Decoder) Decoder

WithCharset replaces the character set map used by the Decoder.

func (Decoder) WithExtCharset

func (d Decoder) WithExtCharset(ext charset.Decoder) Decoder

WithExtCharset replaces the extension 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

func (e *Encoder) Encode(src []byte) ([]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 (Encoder) WithCharset

func (e Encoder) WithCharset(set charset.Encoder) Encoder

WithCharset replaces the character set map used by the Encoder.

func (Encoder) WithExtCharset

func (e Encoder) WithExtCharset(ext charset.Encoder) Encoder

WithExtCharset replaces the extension 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.

Directories

Path Synopsis
Package charset provides encoders and decoders for GSM character sets.
Package charset provides encoders and decoders for GSM character sets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL