Documentation ¶
Overview ¶
Package pdu implements data encoding schemes described in 3GPP TS 23.040.
Such schemes include:
- GSM 7-Bit text encoding,
- UCS2 (UTF-16) text encoding, and
- semi-octet encoding of integers.
Index ¶
- Constants
- Variables
- func Decode(octet byte) int
- func Decode7Bit(octets []byte) (str string, err error)
- func DecodeSemi(octets []byte) []int
- func DecodeSemiAddress(octets []byte) (str string)
- func DecodeUcs2(octets []byte, startsWithHeader bool) (str string, err error)
- func Encode(value int) byte
- func Encode7Bit(str string) []byte
- func EncodeSemi(chunks ...uint64) []byte
- func EncodeUcs2(str string) []byte
- func Is7BitEncodable(s string) bool
- func Swap(octet byte) byte
Constants ¶
const ( Esc byte = 0x1B // Esc code. Sub byte = 0x1A // Ctrl+Z code. CR byte = 0x0D // <CR> code. )
Variables ¶
var ErrIncorrectDataLength = errors.New("decode ucs2: incorrect data length in first entry of octets")
ErrIncorrectDataLength happens when the length of octets is less than the header, defined by the first entry of the octets.
var ErrUnevenNumber = errors.New("decode ucs2: uneven number of octets")
ErrUnevenNumber happens when the number of octets (bytes) in the input is uneven.
var ErrUnexpectedByte = errors.New("7bit decode: met an unexpected byte")
ErrUnexpectedByte happens when someone tries to decode non GSM 7-bit encoded string.
Functions ¶
func Decode7Bit ¶
Decode7Bit decodes the given GSM 7-bit packed octet data (3GPP TS 23.038) into an UTF-8 encoded string.
func DecodeSemi ¶
DecodeSemi unpacks numerical chunks from the given semi-octet encoded data.
func DecodeSemiAddress ¶
DecodeSemiAddress unpacks phone numbers from the given semi-octet encoded data. This method is different from DecodeSemi because a 0x00 byte should be interpreted as two distinct digits. There 0x00 will be "00".
func DecodeUcs2 ¶
DecodeUcs2 decodes the given UCS2 (UTF-16) octet data into a UTF-8 encoded string.
func Encode7Bit ¶
Encode7Bit encodes the given UTF-8 text into GSM 7-bit (3GPP TS 23.038) encoding with packing. Invalid characters outside the 7-bit encoding and shift table are replaced with "?".
func EncodeSemi ¶
EncodeSemi packs the given numerical chunks in a semi-octet representation as described in 3GPP TS 23.040.
func EncodeUcs2 ¶
EncodeUcs2 encodes the given UTF-8 text into UCS2 (UTF-16) encoding and returns the produced octets.
func Is7BitEncodable ¶
Is7BitEncodable reports whether s can be encoded using GSM 7-bit encoding with default alphabet, without replacing or omitting characters.
Types ¶
This section is empty.