{"id":15411875,"url":"https://github.com/nkristek/go-senml","last_synced_at":"2025-04-19T11:33:02.448Z","repository":{"id":143478134,"uuid":"94776400","full_name":"nkristek/go-senml","owner":"nkristek","description":"A go library to parse SenML messages (RFC 8428)","archived":false,"fork":false,"pushed_at":"2019-11-06T23:57:38.000Z","size":43,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T07:21:52.277Z","etag":null,"topics":["go","golang","hacktoberfest","rfc-8428","senml"],"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/nkristek.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":"2017-06-19T12:52:23.000Z","updated_at":"2025-02-21T19:28:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"2fd37c57-d804-44d0-9740-4002c42c5b74","html_url":"https://github.com/nkristek/go-senml","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkristek%2Fgo-senml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkristek%2Fgo-senml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkristek%2Fgo-senml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkristek%2Fgo-senml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nkristek","download_url":"https://codeload.github.com/nkristek/go-senml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249685173,"owners_count":21310558,"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":["go","golang","hacktoberfest","rfc-8428","senml"],"created_at":"2024-10-01T16:50:28.880Z","updated_at":"2025-04-19T11:33:02.427Z","avatar_url":"https://github.com/nkristek.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-senml\n\n[![CI Status](https://github.com/nkristek/go-senml/workflows/CI/badge.svg)](https://github.com/nkristek/go-senml/actions)\n[![GoDoc](https://godoc.org/github.com/nkristek/go-senml?status.svg)](https://godoc.org/github.com/nkristek/go-senml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/nkristek/go-senml)](https://goreportcard.com/report/github.com/nkristek/go-senml)\n\nA go library to parse SenML records. It currently supports JSON and XML.\n\nThis library implements [RFC 8428](https://tools.ietf.org/rfc/rfc8428.txt) (SenML version 10).\n\n## Install\n```sh\ngo get github.com/nkristek/go-senml\n```\n\n## Import\n```go\nimport(\n\t\"github.com/nkristek/go-senml\"\n)\n```\n\n## Usage\n```go\n// parse using the encoding format\nmessage, err := senml.Decode(payload, senml.JSON)\nif err != nil {\n\t// process error\n}\n\n// resolve the message (resolve base attributes, convert relative to absolute time etc.)\nresolvedMessage, err := message.Resolve()\nif err != nil {\n\t// process error\n}\n\n// encode a new message\nencodedMessage, err := message.Encode(senml.JSON)\nif err != nil {\n\t// process error\n}\n```\n\n## Error handling\n\nIf `Resolve()` returns an error it can have one of the following types:\n\n- `InvalidNameError`\n- `UnsupportedVersionError`\n- `DifferentVersionError`\n- `MissingValueError`\n\nLikewise, the `Encode()` and `Decode()` functions return an error of type `UnsupportedFormatError` if it was called with an unsupported format.\n\nThe error types provide extra values to parse the exact reason in code. If you need to check on the specific reason on why resolving the message has failed, the following `switch` statement should suffice: \n\n```go\n_, err := message.Resolve()\nif err != nil {\n\tswitch err.(type) {\n\tcase *senml.InvalidNameError:\n\t\t// do something\n\t\t// for example:\n\t\tinvalidNameError := err.(*senml.InvalidNameError)\n\t\tswitch invalidNameError.Reason {\n\t\tcase senml.FirstCharacterInvalid:\n\t\t\tbreak\n\t\tcase senml.ContainsInvalidCharacter:\n\t\t\tbreak\n\t\tcase senml.Empty:\n\t\t\tbreak\n\t\t}\n\tcase *senml.UnsupportedVersionError:\n\t\t// do something\n\t\tbreak\n\tcase *senml.DifferentVersionError:\n\t\t// do something\n\t\tbreak\n\tcase *senml.MissingValueError:\n\t\t// do something\n\t\tbreak\n\tdefault:\n\t\tbreak\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnkristek%2Fgo-senml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnkristek%2Fgo-senml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnkristek%2Fgo-senml/lists"}