{"id":15644946,"url":"https://github.com/warthog618/sms","last_synced_at":"2025-06-20T18:05:27.591Z","repository":{"id":88433792,"uuid":"125146800","full_name":"warthog618/sms","owner":"warthog618","description":"A Go library for encoding and decoding SMSs","archived":false,"fork":false,"pushed_at":"2024-11-27T02:09:27.000Z","size":267,"stargazers_count":67,"open_issues_count":0,"forks_count":24,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-24T11:06:23.179Z","etag":null,"topics":["conversion","decoder","decoding","encoder","encoding","go","golang","golang-library","gsm-modem","sms","sms-deliver-tpdus","tpdu"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/warthog618.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-14T02:58:48.000Z","updated_at":"2025-05-22T09:26:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"9561cb0e-114b-4645-b6dd-c54a45b84e17","html_url":"https://github.com/warthog618/sms","commit_stats":{"total_commits":122,"total_committers":2,"mean_commits":61.0,"dds":"0.016393442622950838","last_synced_commit":"86c5a1263a87175abf43ef01008b88e1a50ffc71"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/warthog618/sms","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warthog618%2Fsms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warthog618%2Fsms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warthog618%2Fsms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warthog618%2Fsms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/warthog618","download_url":"https://codeload.github.com/warthog618/sms/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warthog618%2Fsms/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260993715,"owners_count":23094268,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conversion","decoder","decoding","encoder","encoding","go","golang","golang-library","gsm-modem","sms","sms-deliver-tpdus","tpdu"],"created_at":"2024-10-03T12:03:37.979Z","updated_at":"2025-06-20T18:05:22.578Z","avatar_url":"https://github.com/warthog618.png","language":"Go","readme":"# sms\n\nA Go library for encoding and decoding SMSs.\n\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/warthog618/sms)\n[![Build Status](https://travis-ci.org/warthog618/sms.svg)](https://travis-ci.org/warthog618/sms)\n[![Coverage Status](https://coveralls.io/repos/github/warthog618/sms/badge.svg?branch=master)](https://coveralls.io/github/warthog618/sms?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/warthog618/sms)](https://goreportcard.com/report/github.com/warthog618/sms)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/warthog618/sms/blob/master/LICENSE)\n\nsms is a Go library for encoding and decoding SMS TPDUs, as specified in 3GPP TS 23.040 and 3GPP TS 23.038.\n\nThe initial impetus was to provide functionality to send and receive SMSs via a\nGSM modem, but the library may be generally useful anywhere encoding and\ndecoding SMS TPDUs or their fields is required.\n\n## Features\n\nSupports the following functionality:\n\n- Creation of SMS TPDUs from UTF-8 strings, including emoji's 😁\n- Segmentation of long messages into several concatenated SMS TPDUs\n- Automatic selection of alphabet and language when encoding\n- Decoding of SMS TPDUs into UTF-8 strings\n- Reassembly of concatenated SMS TPDUs into a long message\n- Support for all GSM character sets\n- Encoding and decoding SMS TPDUs in PDU mode for exchange with GSM modems\n\n## Usage\n\n```go\nimport \"github.com/warthog618/sms\"\n```\n\nIn the following usage examples the error handling is omitted for brevity.\n\n### Encode\n\nCreating the TPDUs to contain a message is referred to as encoding.\n\nA one-off message can be encoded using *sms.Encode*:\n\n```go\ntpdus, _ := sms.Encode([]byte(\"hello world\"))\nfor _, p := range tpdus {\n    b, _ := p.MarshalBinary()\n    // send binary TPDU...\n}\n```\n\nSending multiple messages requires maintaining multiple counter fields and\nencoding them in the TPDU.  This is performed by an *sms.Encoder*:\n\n```go\ne := sms.NewEncoder()\nfor {\n    msg := \u003c- msgChan\n    tpdus, _ := e.Encode(msg)\n    for _, p := range tpdus {\n        b, _ := p.MarshalBinary()\n        // send binary TPDU...\n    }\n}\n```\n\n### Unmarshal\n\nReassembling received TPDUs into a complete message is a multi-step process.\nThe first step is to unmarhsal the binary SMS TPDU into a TPDU object using\n*sms.Unmarshal*:\n\n```go\npdu, _ := sms.Unmarshal(bintpdu)\n```\n\n### Decode\n\nA single segment TPDU can be decoded using *sms.Decode*:\n\n```go\nmsg, _ := sms.Decode([]*tpdu.TPDUs{pdu})\n```\n\nFor concatenated messages, the set of TPDUs containing a message is reassembled\ninto a complete message using *sms.Decode*:\n\n```go\nmsg, _ := sms.Decode(tpdus)\n```\n\n### Collect\n\nThe segments of concatenated messages must be collected before they can be\ndecoded.  The Collector collects received segments and returns the complete set\nonce the final segment is received.\n\n```go\nc := sms.NewCollector()\nfor {\n    bintpdu := \u003c- pduChan\n    pdu, _ := sms.Unmarshal(bintpdu)\n    tpdus, _ := c.Collect(pdu)\n    if len(tpdus) \u003e 0 {\n        msg, _ := sms.Decode(tpdus)\n        // handle msg...\n    }\n}\n```\n\n### Options\n\nThe core API is aimed at the most common use cases, those performed to the\nmobile station. e.g. By default, *sms.Encode* creates an SMS-SUBMIT TPDU and\nonly uses the default character set.  By default, *sms.Decode* uses all\ncharacter sets.  By default, *sms.Unmarshal* assumes the TPDU is mobile\nterminating.\n\nThe behaviour of the core API functions can be altered for other use cases\nusing optional parameters.\n\ne.g. to specify the destination number for a SMS-SUBMIT message:\n\n```go\ntpdus, _ := sms.Encode(\"hello\",sms.To(\"12345\"))\n```\n\nor to encode a message using a particular character set, if necessary:\n\n```go\ntpdus, _ := sms.Encode(\"hello ٻ\",sms.WithCharset(charset.Urdu))\n```\n\nor to specify the encoding of a SMS-DELIVER message:\n\n```go\ntpdus, _ := sms.Encode(\"hello\",sms.AsDeliver,sms.From(\"12345\"))\n```\n\nor to unmarshal a TPDU from the mobile station:\n\n```go\npdu, _ := sms.Unmarshal(bintpdu,sms.AsMO)\n```\n\nThe full set of supplied options:\n\nOption | Category | Description\n---|---|---\n*WithReassemblyTimeout(duration,handler)*|Collect|Limit the time allowed to wait for the TPDUs of a complete reassembly\n*WithTemplate(tpdu)*|Encode|Use the provided TPDU as the template for encoded TPDUs.\n*WithTemplateOption(tpdu.Option)*|Encode|Apply the provided option to the template TPDU during encoding.\n*To(number)*|Encode|Set the DA of the encoded TPDU to the number provided\n*From(number)*|Encode|Set the OA of the encoded TPDU to the number provided\n*WithAllCharsets*|Decode,Encode|Make all GSM7 character sets available\n*WithDefaultCharset*|Decode,Encode|Make only the default character set available\n*WithCharset(nli...)*|Decode,Encode|Make the specified character set(s) available\n*WithLockingCharset(nli...)*|Decode,Encode|Make the specified character set(s) available as a locking character set\n*WithShiftCharset(nli...)*|Decode,Encode|Make the specified character set(s) available as a shift character set\n*AsSubmit*|Encode|Encode the TPDU as a SMS-SUBMIT (default)\n*AsDeliver*|Encode|Encode the TPDU as a SMS-DELIVER\n*As8Bit*|Encode|Force the encoding of user data as 8-bit\n*AsUCS2*|Encode|Force the encoding of user data as UCS-2\n*AsMO*|Unmarshal|Treat the TPDU as originating from the mobile station\n*AsMT*|Unmarshal|Treat the TPDU as terminating at the mobile station (default)\n\n## Tools\n\nThe [cmd](cmd) directory contains basic commands tools to exercise, debug and\ndemonstrate the core functionality of the library, including:\n\n- encoding messages into SMS-SUBMIT TPDUs [(smssubmit)](cmd/smssubmit/smssubmit.go)\n- decoding SMS-DELIVER TPDUs into messages [(smsdeliver)](cmd/smsdeliver/smsdeliver.go)\n- decoding arbitrary TPDUs [(smsdecode)](cmd/smsdecode/smsdecode.go)\n- displaying supported character sets [(charsets)](cmd/charsets/charsets.go).\n\nThe following examples demonstrate the example commands, and their code provides some examples of using the library.\n\n### Submit Encoding\n\nCreating an SMS to send:\n\n```shell\n$ smssubmit -number 12345 -message \"Hello world\"\nSubmit TPDU:\n010105912143f500000bc8329bfd06dddf723619\n```\n\nLong messages are split into a concatenated message spanning several TPDUs:\n\n```shell\nsmssubmit -number 12345 -message \"this is a very long message that does not fit in a single SMS message, at least it will if I keep adding more to it as 160 characters is more than you might think 😁\"\nSubmit TPDU 1:\n410105912143f500088c050003010301007400680069007300200069007300200061002000760065007200790020006c006f006e00670020006d0065007300730061006700650020007400680061007400200064006f006500730020006e006f0074002000660069007400200069006e00200061002000730069006e0067006c006500200053004d00530020006d0065007300730061\nSubmit TPDU 2:\n410205912143f500088c05000301030200670065002c0020006100740020006c0065006100730074002000690074002000770069006c006c002000690066002000490020006b00650065007000200061006400640069006e00670020006d006f0072006500200074006f0020006900740020006100730020003100360030002000630068006100720061006300740065007200730020\nSubmit TPDU 3:\n410305912143f5000844050003010303006900730020006d006f007200650020007400680061006e00200079006f00750020006d00690067006800740020007400680069006e006b0020d83dde01\n```\n\n### Deliver Decoding\n\nDecoding an SMS received from a GSM modem in PDU mode:\n\n```shell\n$ smsdeliver -p 07911614220991F1040B911605935713F200008140806113912304D7F79B0E\n+61503975312: Woot\n```\n\n### Concatenated Message Decoding\n\nConcatenating and displaying a message split into multiple SMS-DELIVER TPDUs.\n\n```shell\n$ smsdeliver 400B911605935713F20008814080611373238C050003C00301007400680069007300200069007300200061002000760065007200790020006C006F006E00670020006D0065007300730061006700650020007400680061007400200064006F006500730020006E006F0074002000660069007400200069006E00200061002000730069006E0067006C006500200053004D00530020006D0065007300730061 400B911605935713F20008814080611373238C050003C0030200670065002C0020006100740020006C0065006100730074002000690074002000770069006C006C002000690066002000490020006B00650065007000200061006400640069006E00670020006D006F0072006500200074006F0020006900740020006100730020003100360030002000630068006100720061006300740065007200730020 440B911605935713F200088140806113832344050003C00303006900730020006D006F007200650020007400680061006E00200079006F00750020006D00690067006800740020007400680069006E006B0020D83DDE01\n+61503975312: this is a very long message that does not fit in a single SMS message, at least it will if I keep adding more to it as 160 characters is more than you might think 😁\n```\n\n### General TPDU Decoding\n\nDecoding the Submit TPDU created above:\n\n```shell\n$ smsdecode -o 010105912143f500000bc8329bfd06dddf723619\nTPDU: SMS-SUBMIT\nTP-MTI: 0x01 Submit\nTP-RD: false\nTP-VPF: 0x00 Not Present\nTP-RP: false\nTP-UDHI: false\nTP-SRR: false\nTP-MR: 1\nTP-DA: +12345\nTP-PID: 0x00\nTP-DCS: 0x00 7bit\nTP-VP: Not Present\nTP-UD: 00000000  48 65 6c 6c 6f 20 77 6f  72 6c 64                 |Hello world|\n```\n\nDecoding the Deliver TPDU above:\n\n```shell\n$ smsdecode -p 07911614220991F1040B911605935713F200008140806113912304D7F79B0E\nSMSC: +61412290191\nTPDU: SMS-DELIVER\nTP-MTI: 0x00 Deliver\nTP-MMS: true\nTP-LP: false\nTP-RP: false\nTP-UDHI: false\nTP-SRI: false\nTP-OA: +61503975312\nTP-PID: 0x00\nTP-DCS: 0x00 7bit\nTP-SCTS: 2018-04-08 16:31:19 +0800\nTP-UD: 00000000  57 6f 6f 74                                       |Woot|\n```\n\nDecoding the first Deliver TPDU of the concatenated message above:\n\n```shell\n$ smsdecode 400B911605935713F20008814080611373238C050003C00301007400680069007300200069007300200061002000760065007200790020006C006F006E00670020006D0065007300730061006700650020007400680061007400200064006F006500730020006E006F0074002000660069007400200069006E00200061002000730069006E0067006C006500200053004D00530020006D0065007300730061\nTPDU: SMS-DELIVER\nTP-MTI: 0x00 Deliver\nTP-MMS: false\nTP-LP: false\nTP-RP: false\nTP-UDHI: true\nTP-SRI: false\nTP-OA: +61503975312\nTP-PID: 0x00\nTP-DCS: 0x08 UCS-2\nTP-SCTS: 2018-04-08 16:31:37 +0800\nTP-UDH: ID: 0  Data: [192 3 1]\nTP-UD: 00000000  00 74 00 68 00 69 00 73  00 20 00 69 00 73 00 20  |.t.h.i.s. .i.s. |\n       00000010  00 61 00 20 00 76 00 65  00 72 00 79 00 20 00 6c  |.a. .v.e.r.y. .l|\n       00000020  00 6f 00 6e 00 67 00 20  00 6d 00 65 00 73 00 73  |.o.n.g. .m.e.s.s|\n       00000030  00 61 00 67 00 65 00 20  00 74 00 68 00 61 00 74  |.a.g.e. .t.h.a.t|\n       00000040  00 20 00 64 00 6f 00 65  00 73 00 20 00 6e 00 6f  |. .d.o.e.s. .n.o|\n       00000050  00 74 00 20 00 66 00 69  00 74 00 20 00 69 00 6e  |.t. .f.i.t. .i.n|\n       00000060  00 20 00 61 00 20 00 73  00 69 00 6e 00 67 00 6c  |. .a. .s.i.n.g.l|\n       00000070  00 65 00 20 00 53 00 4d  00 53 00 20 00 6d 00 65  |.e. .S.M.S. .m.e|\n       00000080  00 73 00 73 00 61                                 |.s.s.a|\n```\n\nDecoding the second Submit TPDU in the concatenated message above:\n\n```shell\nsmsdecode -o 410205912143f500088c05000301030200670065002c0020006100740020006c0065006100730074002000690074002000770069006c006c002000690066002000490020006b00650065007000200061006400640069006e00670020006d006f0072006500200074006f0020006900740020006100730020003100360030002000630068006100720061006300740065007200730020\nTPDU: SMS-SUBMIT\nTP-MTI: 0x01 Submit\nTP-RD: false\nTP-VPF: 0x00 Not Present\nTP-RP: false\nTP-UDHI: true\nTP-SRR: false\nTP-MR: 2\nTP-DA: +12345\nTP-PID: 0x00\nTP-DCS: 0x08 UCS-2\nTP-VP: Not Present\nTP-UDH: ID: 0  Data: [1 3 2]\nTP-UD: 00000000  00 67 00 65 00 2c 00 20  00 61 00 74 00 20 00 6c  |.g.e.,. .a.t. .l|\n       00000010  00 65 00 61 00 73 00 74  00 20 00 69 00 74 00 20  |.e.a.s.t. .i.t. |\n       00000020  00 77 00 69 00 6c 00 6c  00 20 00 69 00 66 00 20  |.w.i.l.l. .i.f. |\n       00000030  00 49 00 20 00 6b 00 65  00 65 00 70 00 20 00 61  |.I. .k.e.e.p. .a|\n       00000040  00 64 00 64 00 69 00 6e  00 67 00 20 00 6d 00 6f  |.d.d.i.n.g. .m.o|\n       00000050  00 72 00 65 00 20 00 74  00 6f 00 20 00 69 00 74  |.r.e. .t.o. .i.t|\n       00000060  00 20 00 61 00 73 00 20  00 31 00 36 00 30 00 20  |. .a.s. .1.6.0. |\n       00000070  00 63 00 68 00 61 00 72  00 61 00 63 00 74 00 65  |.c.h.a.r.a.c.t.e|\n       00000080  00 72 00 73 00 20                                 |.r.s. |\n```\n\n## Subpackages\n\nThe [tpdu](encoding/tpdu) package [![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/warthog618/sms/encoding/tpdu) provides the core TPDU types and conversions to and from their binary form.\n\nThe [pdumode](encoding/pdumode) package [![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/warthog618/sms/encoding/pdumode) provides encoding and decoding of PDUs exchanged with GSM modems in PDU mode.\n\nA number of packages provide functionality to encode and decode TPDU fields:\n\nThe [bcd](encoding/bcd) package [![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/warthog618/sms/encoding/bcd) provides conversions to and from BCD format.\n\nThe [gsm7](encoding/gsm7) package [![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/warthog618/sms/encoding/gsm7) provides conversions to and from 7bit packed user data.\n\nThe [charset](encoding/gsm7/charset) package [![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/warthog618/sms/encoding/gsm7/charset) provides the character sets used to encode user data in GSM 7bit format as specified in 3GPP TS 23.038.\n\nThe [semioctet](encoding/semioctet) package [![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/warthog618/sms/encoding/semioctet) provides conversions to and from semioctet format.\n\nThe [ucs2](encoding/ucs2) package [![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/warthog618/sms/encoding/ucs2) provides conversions between UCS-2 and UTF-8.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarthog618%2Fsms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwarthog618%2Fsms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarthog618%2Fsms/lists"}