charset

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2018 License: MIT Imports: 5 Imported by: 3

README

charset

Package charset implements data encoding schemes described in 3GPP TS 23.040. Such schemes include: GSM 7-Bit text encoding, UCS2 (UTF-16) text encoding, semi-octet encoding of integers.

Extracted from https://github.com/xlab/at

Documentation

Overview

Package charset implements data encoding schemes described in 3GPP TS 23.040. Such schemes include: GSM 7-Bit text encoding, UCS2 (UTF-16) text encoding, semi-octet encoding of integers.

Index

Constants

View Source
const (

	// Esc code.
	Esc byte = 0x1B
	// Ctrl+Z code.
	Sub byte = 0x1A
	// <CR> code.
	CR byte = 0x0D
)

Variables

View Source
var (
	// Common errors.
	ErrUnevenLength = errors.New("parse octets: uneven length of string")
	ErrUnexpected   = errors.New("parse octets: met a non-HEX rune in string")
	// ErrUnexpectedByte happens when someone tries to decode non GSM 7-bit encoded string.
	ErrUnexpectedByte = errors.New("7bit decode: met an unexpected byte")
)
View Source
var ErrUnevenNumber = errors.New("decode ucs2: uneven number of octets")

ErrUnevenNumber happens when the number of octets (bytes) in the input is uneven.

Functions

func Decode7Bit

func Decode7Bit(octets []byte) (str string, err error)

Decode7Bit decodes the given GSM 7-bit octet data (3GPP TS 23.038) into a UTF-8 encoded string.

func DecodeSemi

func DecodeSemi(octets []byte) []int

DecodeSemi unpacks numerical chunks from the given semi-octet encoded data.

func DecodeSemiAddress

func DecodeSemiAddress(octets []byte) (str string)

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

func DecodeUcs2(octets []byte) (str string, err error)

DecodeUcs2 decodes the given UCS2 (UTF-16) octet data into a UTF-8 encoded string.

func Encode7Bit

func Encode7Bit(str string) []byte

Encode7Bit encodes the given UTF-8 text into GSM 7-bit (3GPP TS 23.038) encoding.

func EncodeSemi

func EncodeSemi(chunks ...uint64) []byte

EncodeSemi packs the given numerical chunks in a semi-octet representation as described in 3GPP TS 23.040.

func EncodeUcs2

func EncodeUcs2(str string) []byte

EncodeUcs2 encodes the given UTF-8 text into UCS2 (UTF-16) encoding and returns the produced octets.

func IsGsmAlpha

func IsGsmAlpha(str string) bool

IsGsmAlpha returns true if the string contains only valid GSM 7-bit characters

func Pack7Bit

func Pack7Bit(raw7 []byte) []byte

Pack7Bit returns a 7-bit packing

func ParseOddHexStr

func ParseOddHexStr(hex string) ([]byte, error)

parseOddHexStr parses the hex-string of odd length into bytes.

func Unpack7Bit

func Unpack7Bit(pack7 []byte) []byte

Types

This section is empty.

Jump to

Keyboard shortcuts

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