Documentation ¶
Overview ¶
Package sms provides encoders and decoders for SMS PDUs.
Index ¶
- Variables
- func Decode(segments []*tpdu.TPDU, options ...DecodeOption) ([]byte, error)
- func Encode(msg []byte, options ...EncoderOption) ([]tpdu.TPDU, error)
- func IsCompleteMessage(segments []*tpdu.TPDU) bool
- func Unmarshal(src []byte, options ...UnmarshalOption) (*tpdu.TPDU, error)
- type AllCharsetsOption
- type CharsetOption
- type Collector
- type CollectorOption
- type Counter
- type DecodeConfig
- type DecodeOption
- type Encoder
- type EncoderOption
- type LockingCharsetOption
- type ShiftCharsetOption
- type UnmarshalConfig
- type UnmarshalOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClosed indicates that the collector has been closed and is no longer // accepting PDUs. ErrClosed = errors.New("closed") // ErrDcsConflict indicates the required encoding for user data conflicts with the // encoding specified in the template TPDU DCS. ErrDcsConflict = errors.New("DCS conflict") // ErrDuplicateSegment indicates a segment has arrived for a reassembly // that already has that segment. // The segments are duplicates in terms of their concatentation information. // They may differ in other fields, particularly UD, but those fields // cannot be used to determine which of the two may better fit the // reassembly, so the first is kept and the second discarded. ErrDuplicateSegment = errors.New("duplicate segment") // ErrReassemblyInconsistency indicates a segment has arrived for a // reassembly that has a seqno greater than the number of segments in the // reassembly. ErrReassemblyInconsistency = errors.New("reassembly inconsistency") )
var ( // AsSubmit indicates that generated PDUs will be of type SmsSubmit. AsSubmit = templateOption{tpdu.SmsSubmit} // AsDeliver indicates that generated PDUs will be of type SmsDeliver. AsDeliver = templateOption{tpdu.SmsDeliver} // As8Bit indicates that generated PDUs encode user data as 8bit. As8Bit = templateOption{tpdu.Dcs8BitData} // AsUCS2 indicates that generated PDUs encode user data as UCS2. AsUCS2 = templateOption{tpdu.DcsUCS2Data} // AsMO indicates that the TPDU originated from the mobile station. AsMO = directionOption{tpdu.MO} // AsMT indicates that the TPDU as destined for the mobile station. AsMT = directionOption{tpdu.MT} // WithAllCharsets specifies that all character sets are available for // encoding or decoding. // // This is the default policy for decoding. WithAllCharsets = AllCharsetsOption{} // WithDefaultCharset specifies that only the default character set is // available for encoding or decoding. // // This is the default policy for encoding. WithDefaultCharset = CharsetOption{} )
Functions ¶
func Decode ¶
func Decode(segments []*tpdu.TPDU, options ...DecodeOption) ([]byte, error)
Decode returns the UTF-8 message contained in a set of TPDUs.
For concatenated messages the segments assumed to be the component TPDUs, in correct order. This is the case for segments returned by the Collector. It can be tested using IsCompleteMessage.
func Encode ¶
func Encode(msg []byte, options ...EncoderOption) ([]tpdu.TPDU, error)
Encode builds a set of TPDUs containing the message.
Long messages are split into multiple concatenated TPDUs, while short messages may fit in one.
By default messages are encoded into SMS-SUBMIT TPDUs. This behaviour may be overridden via options.
For 8-bit encoding the message is encoded as is.
For 7-bit encoding the message is assumed to contain UTF-8.
For explicit UCS-2 encoding the message is assumed to contain UTF-16, encoded as an array of bytes. This can be created from an array of UTF-16 runes using ucs2.Encode.
For implicit UCS-2 encoding (the fallback with 7-bit fails) the message is assumed to contain UTF-8.
func IsCompleteMessage ¶
IsCompleteMessage confirms that the TPDUs contain all the sgements required to reassemble a complete message and are in the correct order.
Types ¶
type AllCharsetsOption ¶
type AllCharsetsOption struct{}
AllCharsetsOption specifies that all charactersets are available for encoding.
func (AllCharsetsOption) ApplyEncoderOption ¶
func (o AllCharsetsOption) ApplyEncoderOption(e *Encoder)
ApplyEncoderOption applies the AllCharsetsOption to an Encoder.
type CharsetOption ¶
type CharsetOption struct {
// contains filtered or unexported fields
}
CharsetOption defines the character sets available for encoding or decoding.
func (CharsetOption) ApplyDecodeOption ¶
func (o CharsetOption) ApplyDecodeOption(cc *DecodeConfig)
ApplyDecodeOption applies the CharsetOption to decoding.
func (CharsetOption) ApplyEncoderOption ¶
func (o CharsetOption) ApplyEncoderOption(e *Encoder)
ApplyEncoderOption applies the CharsetOption to an Encoder.
type Collector ¶
type Collector struct { sync.Mutex // covers pipes and closing closed // contains filtered or unexported fields }
Collector contains reassembly pipes that buffer concatenated TPDUs until a full set is available to be concatenated.
func NewCollector ¶
func NewCollector(options ...CollectorOption) *Collector
NewCollector creates a Collector.
func (*Collector) Close ¶
func (c *Collector) Close()
Close shuts down the Collector and all active pipes.
type CollectorOption ¶
type CollectorOption interface {
ApplyCollectorOption(*Collector)
}
CollectorOption alters the behaviour of a Collector.
func WithReassemblyTimeout ¶
func WithReassemblyTimeout(d time.Duration, eh func([]*tpdu.TPDU)) CollectorOption
WithReassemblyTimeout limits the time allowed for a collection of TPDUs to be collected.
If the timer expires before the collection is complete then the collected TPDUs are passed to the expiryHandler. The expiry handler can be nil in which case the collected TPDUs are simply discarded.
A zero duration disables the timeout.
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is an implementation of the tpdu.Counter interface.
It also provides a Read method on the current value for diagnostic purposes.
type DecodeConfig ¶
type DecodeConfig struct {
// contains filtered or unexported fields
}
DecodeConfig contains configuration option for Decode.
type DecodeOption ¶
type DecodeOption interface {
ApplyDecodeOption(*DecodeConfig)
}
DecodeOption defines options for Decode.
type Encoder ¶
type Encoder struct { // MsgCount is the number of TPDUs encoded. MsgCount tpdu.Counter // ConcatRef is the number of multi-segment messages encoded. ConcatRef tpdu.Counter // contains filtered or unexported fields }
Encoder builds SMS TPDUs from simple inputs such as the destination number and the message in a UTF8 form.
func (Encoder) Encode ¶
Encode builds a set of TPDUs containing the message.
Long messages are split into multiple concatenated TPDUs, while short messages may fit in one.
By default messages are encoded into SMS-DELIVER TPDUs. This behaviour may be overridden via options, either to NewEncoder or Encode.
For 8-bit encoding the message is encoded as is.
For 7-bit encoding the message is assumed to contain UTF-8.
For explicit UCS-2 encoding the message is assumed to contain UTF-16, encoded as an array of bytes. This can be created from an array of UTF-16 runes using ucs2.Encode.
For implicit UCS-2 encoding (the fallback with 7-bit fails) the message is assumed to contain UTF-8.
type EncoderOption ¶
type EncoderOption interface {
ApplyEncoderOption(*Encoder)
}
EncoderOption is an optional mutator for the Encoder.
func WithTemplate ¶
func WithTemplate(t tpdu.TPDU) EncoderOption
WithTemplate specifies the TPDU to be used as the template for encoding.
func WithTemplateOption ¶
func WithTemplateOption(option tpdu.Option) EncoderOption
WithTemplateOption wraps a TPDU option in a TemplateOption so it can be applied to an Encoder template PDU.
type LockingCharsetOption ¶
type LockingCharsetOption struct {
// contains filtered or unexported fields
}
LockingCharsetOption defines the locking character sets available for encoding or decoding.
func WithLockingCharset ¶
func WithLockingCharset(nli ...int) LockingCharsetOption
WithLockingCharset creates an LockingCharsetOption.
func (LockingCharsetOption) ApplyDecodeOption ¶
func (o LockingCharsetOption) ApplyDecodeOption(cc *DecodeConfig)
ApplyDecodeOption applies the LockingCharsetOption to decoding.
func (LockingCharsetOption) ApplyEncoderOption ¶
func (o LockingCharsetOption) ApplyEncoderOption(e *Encoder)
ApplyEncoderOption applies the LockingCharsetOption to an Encoder.
type ShiftCharsetOption ¶
type ShiftCharsetOption struct {
// contains filtered or unexported fields
}
ShiftCharsetOption defines the shift character sets available for encoding or decoding.
func WithShiftCharset ¶
func WithShiftCharset(nli ...int) ShiftCharsetOption
WithShiftCharset creates an ShiftCharsetOption.
func (ShiftCharsetOption) ApplyDecodeOption ¶
func (o ShiftCharsetOption) ApplyDecodeOption(cc *DecodeConfig)
ApplyDecodeOption applies the ShiftCharsetOption to decoding.
func (ShiftCharsetOption) ApplyEncoderOption ¶
func (o ShiftCharsetOption) ApplyEncoderOption(e *Encoder)
ApplyEncoderOption applies the ShiftCharsetOption to an Encoder.
type UnmarshalConfig ¶
type UnmarshalConfig struct {
// contains filtered or unexported fields
}
UnmarshalConfig contains configuration options for Unmarshal.
type UnmarshalOption ¶
type UnmarshalOption interface {
ApplyUnmarshalOption(*UnmarshalConfig)
}
UnmarshalOption defines options for Unmarhsal.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
smscounter
smscounter provides an example of generating output similar to that generated by github.com/danxexe/sms-counter.
|
smscounter provides an example of generating output similar to that generated by github.com/danxexe/sms-counter. |
smsdecode
smsdecode provides an example of unmarshalling and displaying a SMS TPDU.
|
smsdecode provides an example of unmarshalling and displaying a SMS TPDU. |
smsdeliver
smsdeliver provides an example of extracting a message from a set of SMS-DELIVER TPDUs.
|
smsdeliver provides an example of extracting a message from a set of SMS-DELIVER TPDUs. |
smssubmit
smssubmit provides an example of encoding a message into a set of SMS-SUBMIT TPDUs.
|
smssubmit provides an example of encoding a message into a set of SMS-SUBMIT TPDUs. |
encoding
|
|
bcd
Package bcd provides conversions to and from BCD format.
|
Package bcd provides conversions to and from BCD format. |
gsm7
Package gsm7 provides conversions to and from 7bit packed user data.
|
Package gsm7 provides conversions to and from 7bit packed user data. |
gsm7/charset
Package charset provides encoders and decoders for GSM character sets.
|
Package charset provides encoders and decoders for GSM character sets. |
pdumode
Package pdumode provides functions to encode and decode PDU mode frames exchanged with a GSM modem in PDU mode.
|
Package pdumode provides functions to encode and decode PDU mode frames exchanged with a GSM modem in PDU mode. |
semioctet
Package semioctet provides conversions to and from semioctet format.
|
Package semioctet provides conversions to and from semioctet format. |
tpdu
Package tpdu provides the TPDU type and conversions to and from its binary form.
|
Package tpdu provides the TPDU type and conversions to and from its binary form. |
ucs2
Package ucs2 provides conversions between UCS-2 and UTF-8.
|
Package ucs2 provides conversions between UCS-2 and UTF-8. |
internal
|
|