{"id":35173896,"url":"https://github.com/danclive/nson-go","last_synced_at":"2026-01-20T12:00:39.169Z","repository":{"id":137816623,"uuid":"170317859","full_name":"danclive/nson-go","owner":"danclive","description":"NSON is a lightweight data-interchange format like JSON or BSON","archived":false,"fork":false,"pushed_at":"2026-01-14T14:12:22.000Z","size":82,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-14T18:01:05.547Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/danclive.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-02-12T12:55:05.000Z","updated_at":"2026-01-14T14:05:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"a8b9f4dc-5ff4-484b-8c59-39bf9287966d","html_url":"https://github.com/danclive/nson-go","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/danclive/nson-go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danclive%2Fnson-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danclive%2Fnson-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danclive%2Fnson-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danclive%2Fnson-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danclive","download_url":"https://codeload.github.com/danclive/nson-go/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danclive%2Fnson-go/sbom","scorecard":{"id":318612,"data":{"date":"2025-08-11","repo":{"name":"github.com/danclive/nson-go","commit":"b661daab94f8a8ae3f98e9144f386c66b8f2e96d"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Code-Review","score":0,"reason":"Found 0/21 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T00:52:37.384Z","repository_id":137816623,"created_at":"2025-08-18T00:52:37.384Z","updated_at":"2025-08-18T00:52:37.384Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28603294,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T10:46:13.255Z","status":"ssl_error","status_checked_at":"2026-01-20T10:42:51.865Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2025-12-28T21:48:01.026Z","updated_at":"2026-01-20T12:00:39.074Z","avatar_url":"https://github.com/danclive.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NSON-Go\n\n高性能的 NSON (Network Serialization Object Notation) 序列化库。\n\n## 特性\n\n- 🚀 **高性能** - Marshal ~400ns/op, Unmarshal ~232ns/op\n- 💪 **强类型系统** - 18 种精确类型，8 种整数类型保证精度不丢失\n- 📦 **结构体序列化** - 类似 JSON，支持 struct tag、omitempty、嵌入结构体\n- ⏱️ **时间类型** - time.Time ↔ Timestamp 自动转换（毫秒精度）\n- 🆔 **ID 类型** - nson.Id 唯一标识符，区别于普通 []byte\n- 🎯 **类型安全** - 精确类型匹配，编译时类型检查\n\n## 快速开始\n\n### 安装\n\n```bash\ngo get github.com/danclive/nson-go\n```\n\n### 基本使用\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    nson \"github.com/danclive/nson-go\"\n)\n\ntype User struct {\n    Name     string   `nson:\"name\"`\n    Age      int32    `nson:\"age\"`\n    Email    string   `nson:\"email,omitempty\"`\n    Tags     []string `nson:\"tags\"`\n}\n\nfunc main() {\n    // 序列化\n    user := User{\n        Name: \"Alice\",\n        Age:  28,\n        Tags: []string{\"developer\", \"golang\"},\n    }\n\n    m, err := nson.Marshal(user)\n    if err != nil {\n        panic(err)\n    }\n\n    // 反序列化\n    var result User\n    err = nson.Unmarshal(m, \u0026result)\n    if err != nil {\n        panic(err)\n    }\n\n    fmt.Printf(\"%+v\\n\", result)\n}\n```\n\n## 核心功能\n\n### 强类型系统\n\n精确保留整数类型，不丢失精度：\n\n```go\ntype Data struct {\n    Int8   int8   `nson:\"i8\"`     // -\u003e I8 (1 byte)\n    Int16  int16  `nson:\"i16\"`    // -\u003e I16 (2 bytes)\n    Int32  int32  `nson:\"i32\"`    // -\u003e I32 (4 bytes)\n    Int64  int64  `nson:\"i64\"`    // -\u003e I64 (8 bytes)\n    Uint8  uint8  `nson:\"u8\"`     // -\u003e U8\n    Uint16 uint16 `nson:\"u16\"`    // -\u003e U16\n    Uint32 uint32 `nson:\"u32\"`    // -\u003e U32\n    Uint64 uint64 `nson:\"u64\"`    // -\u003e U64\n}\n```\n\n### 时间类型\n\ntime.Time 自动转换为 Timestamp（毫秒精度）：\n\n```go\ntype Event struct {\n    Name      string    `nson:\"name\"`\n    CreatedAt time.Time `nson:\"created_at\"`  // -\u003e Timestamp\n    UpdatedAt time.Time `nson:\"updated_at\"`  // -\u003e Timestamp\n}\n\nevent := Event{\n    Name:      \"系统启动\",\n    CreatedAt: time.Now(),\n}\n\nm, _ := nson.Marshal(event)\n// m[\"created_at\"] 是 nson.Timestamp 类型（毫秒时间戳）\n```\n\n### ID 类型\n\nnson.Id 用于唯一标识符，区别于普通二进制数据：\n\n```go\ntype Document struct {\n    DocID   nson.Id `nson:\"doc_id\"`    // -\u003e Id (专用类型)\n    Content []byte  `nson:\"content\"`   // -\u003e Binary (通用二进制)\n}\n\ndoc := Document{\n    DocID: nson.Id{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c},\n}\n```\n\n### Struct Tag\n\n```go\ntype User struct {\n    Name     string `nson:\"name\"`              // 自定义字段名\n    Email    string `nson:\"email,omitempty\"`   // 空值时省略\n    Internal string `nson:\"-\"`                 // 跳过此字段\n}\n```\n\n### 嵌入结构体\n\n```go\ntype BaseEntity struct {\n    ID        nson.Id   `nson:\"id\"`\n    CreatedAt time.Time `nson:\"created_at\"`\n}\n\ntype Article struct {\n    BaseEntity                          // 字段会被展开\n    Title   string `nson:\"title\"`\n    Content string `nson:\"content\"`\n}\n```\n\n### 类型别名支持\n\nNSON 完全支持类型别名（type alias），无需额外转换：\n\n```go\n// 定义类型别名（常见于业务代码中）\ntype QoS uint8\ntype Priority uint8\ntype Status int32\n\nconst (\n    QoS0 QoS = 0\n    QoS1 QoS = 1\n    QoS2 QoS = 2\n)\n\ntype Message struct {\n    Topic    string   `nson:\"topic\"`\n    QoS      QoS      `nson:\"qos\"`        // 直接使用类型别名\n    Priority Priority `nson:\"priority\"`    // 直接使用类型别名\n    Status   Status   `nson:\"status\"`      // 直接使用类型别名\n}\n\n// 无需中间结构体转换，直接序列化\nmsg := Message{\n    Topic:    \"test/topic\",\n    QoS:      QoS1,      // 自动转换为 U8\n    Priority: 1,         // 自动转换为 U8\n    Status:   200,       // 自动转换为 I32\n}\n\nm, _ := nson.Marshal(\u0026msg)\n// QoS, Priority, Status 根据底层类型自动映射到对应的 NSON 类型\n\nvar decoded Message\nnson.Unmarshal(m, \u0026decoded)\n// decoded.QoS == QoS1 (保持原始类型)\n```\n\n**优势：**\n- ✅ 无需创建中间结构体\n- ✅ 避免字段拷贝\n- ✅ 保持类型安全\n- ✅ 零运行时开销\n\n## 类型映射\n\n| Go 类型 | NSON 类型 | 大小 | 说明 |\n|---------|-----------|------|------|\n| `bool` | `Bool` | 1B | 布尔值 |\n| `int8` | `I8` | 1B | 有符号整数 |\n| `int16` | `I16` | 2B | 有符号整数 |\n| `int32`, `int` | `I32` | 4B | 有符号整数 |\n| `int64` | `I64` | 8B | 有符号整数 |\n| `uint8` | `U8` | 1B | 无符号整数 |\n| `uint16` | `U16` | 2B | 无符号整数 |\n| `uint32`, `uint` | `U32` | 4B | 无符号整数 |\n| `uint64` | `U64` | 8B | 无符号整数 |\n| `float32` | `F32` | 4B | 浮点数 |\n| `float64` | `F64` | 8B | 浮点数 |\n| `string` | `String` | 变长 | UTF-8 字符串 |\n| `[]byte` | `Binary` | 变长 | 二进制数据 |\n| `time.Time` | `Timestamp` | 8B | 毫秒时间戳 |\n| `nson.Id` ([]byte) | `Id` | 12B | 唯一标识符 |\n| `[]T` | `Array` | 变长 | 数组 |\n| `map[string]T` | `Map` | 变长 | 映射 |\n| `struct` | `Map` | 变长 | 结构体 |\n| `*T` | `Null` / `T` | - | nil 为 Null，否则为值类型 |\n| `interface{}` | 对应类型 | - | 根据实际值类型映射 |\n\n## 示例\n\n```bash\n# 运行示例\ngo run examples/marshal/marshal_demo.go      # 结构体序列化\ngo run examples/types/types_demo.go          # 类型系统演示\ngo run examples/codec/extended_types_demo.go # 编解码示例\n```\n\n## 测试\n\n```bash\ngo test ./...                                # 运行所有测试\ngo test ./marshal_test/...                   # 运行 marshal 测试\ngo test -bench=. -benchmem ./marshal_test/   # 基准测试\n```\n\n## 性能\n\n基准测试结果（Go 1.20+）：\n\n```\nBenchmarkMarshal-20        399.5 ns/op    572 B/op    11 allocs/op\nBenchmarkUnmarshal-20      232.3 ns/op    152 B/op     3 allocs/op\nBenchmarkRoundTrip-20      643.2 ns/op    724 B/op    14 allocs/op\n```\n\n运行基准测试：\n\n```bash\ngo test -bench=. -benchmem ./marshal_test/\n```\n\n## 与其他格式对比\n\n| 特性 | NSON | JSON | MessagePack | Protocol Buffers |\n|------|------|------|-------------|------------------|\n| 强类型整数 | ✅ 8 种 | ❌ 仅 number | ⚠️ 部分 | ✅ 是 |\n| 浮点类型 | ✅ 2 种 | ❌ 仅 number | ⚠️ 部分 | ✅ 是 |\n| 时间类型 | ✅ Timestamp | ❌ 字符串 | ❌ 扩展 | ⚠️ 需定义 |\n| ID 类型 | ✅ 内置 | ❌ 字符串 | ❌ 无 | ⚠️ 需定义 |\n| Schema | ❌ 无需 | ❌ 无需 | ❌ 无需 | ✅ 需要 |\n| 动态类型 | ✅ 是 | ✅ 是 | ✅ 是 | ❌ 否 |\n| 可读性 | ⚠️ 二进制 | ✅ 文本 | ❌ 二进制 | ❌ 二进制 |\n| 易用性 | ✅ 高 | ✅ 高 | ✅ 高 | ⚠️ 中 |\n\n## 许可证\n\nMIT License - 参见 [LICENSE](./LICENSE) 文件\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanclive%2Fnson-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanclive%2Fnson-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanclive%2Fnson-go/lists"}