{"id":18408965,"url":"https://github.com/msgpack/msgpack-d","last_synced_at":"2025-04-12T21:49:19.854Z","repository":{"id":387796,"uuid":"2191781","full_name":"msgpack/msgpack-d","owner":"msgpack","description":"MessagePack for D / msgpack.org[D]","archived":false,"fork":false,"pushed_at":"2023-11-08T12:47:43.000Z","size":676,"stargazers_count":117,"open_issues_count":22,"forks_count":41,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-12T21:48:54.930Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://msgpack.org/","language":"D","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/msgpack.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_1_0.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2011-08-11T14:58:03.000Z","updated_at":"2025-03-30T09:33:14.000Z","dependencies_parsed_at":"2023-07-05T14:45:31.254Z","dependency_job_id":null,"html_url":"https://github.com/msgpack/msgpack-d","commit_stats":{"total_commits":254,"total_committers":29,"mean_commits":8.758620689655173,"dds":0.2716535433070866,"last_synced_commit":"6857b30aa2fec7145a34796dd202cbf0d001e3c9"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msgpack%2Fmsgpack-d","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msgpack%2Fmsgpack-d/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msgpack%2Fmsgpack-d/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msgpack%2Fmsgpack-d/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msgpack","download_url":"https://codeload.github.com/msgpack/msgpack-d/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248637833,"owners_count":21137538,"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":[],"created_at":"2024-11-06T03:22:51.600Z","updated_at":"2025-04-12T21:49:19.826Z","avatar_url":"https://github.com/msgpack.png","language":"D","readme":"[![CI](https://github.com/msgpack/msgpack-d/actions/workflows/d.yml/badge.svg)](https://github.com/msgpack/msgpack-d/actions/workflows/d.yml)\n\n# MessagePack for D\n\nMessagePack is a binary-based JSON-like serialization library.\n\nMessagePack for D is a pure D implementation of MessagePack.\n\n# Features\n\n* Small size and High performance\n* Zero copy serialization / deserialization\n* Streaming deserializer for non-contiguous IO situation\n* Supports D features (Ranges, Tuples, real type)\n\nNote: The `real` type is only supported in D.\nDon't use the `real` type when communicating with other programming languages.\nNote that `Unpacker` will raise an exception if a loss of precision occurs.\n\n## Current Limitations\n\n* No circular references support\n* If you want to use the LDC compiler, you need at least version 0.15.2 beta2\n\n# Install\n\nUse dub to add it as a dependency:\n\n```sh\n% dub install msgpack-d\n```\n\n# Usage\n\nExample code can be found in the `example` directory.\n\nThe documentation can be found [here](http://msgpack.github.io/msgpack-d/)\n\n## pack / unpack\n\nmsgpack-d is very simple to use. Use `pack` for serialization, and `unpack` for deserialization:\n\n```D\nimport std.file;\nimport msgpack;\n\nstruct S { int x; float y; string z; }\n\nvoid main()\n{\n    S input = S(10, 25.5, \"message\");\n\n    // serialize data\n    ubyte[] inData = pack(input);\n\n    // write data to a file\n    write(\"file.dat\", inData);\n\n    // read data from a file\n    ubyte[] outData = cast(ubyte[])read(\"file.dat\");\n\n    // unserialize the data\n    S target = outData.unpack!S();\n\n    // verify data is the same\n    assert(target.x == input.x);\n    assert(target.y == input.y);\n    assert(target.z == input.z);\n}\n```\n\n### Feature: Skip serialization/deserialization of a specific field.\n\nUse the `@nonPacked` attribute:\n\n```d\nstruct User\n{\n    string name;\n    @nonPacked int level;  // pack / unpack will ignore the 'level' field\n}\n```\n\n### Feature: Use your own serialization/deserialization routines for custom class and struct types.\n\nmsgpack-d provides the functions `registerPackHandler` / `registerUnpackHandler` to allow you\nto use custom routines during the serialization or deserialization of user-defined class and struct types.\nThis feature is especially useful when serializing a derived class object when that object is statically\ntyped as a base class object.\n\nFor example:\n\n```d\nclass Document { }\nclass XmlDocument : Document\n{\n    this() { }\n    this(string name) { this.name = name; }\n    string name;\n}\n\nvoid xmlPackHandler(ref Packer p, ref XmlDocument xml)\n{\n    p.pack(xml.name);\n}\n\nvoid xmlUnpackHandler(ref Unpacker u, ref XmlDocument xml)\n{\n    u.unpack(xml.name);\n}\n\nvoid main()\n{\n    /// Register the 'xmlPackHandler' and 'xmlUnpackHandler' routines for\n    /// XmlDocument object instances.\n    registerPackHandler!(XmlDocument, xmlPackHandler);\n    registerUnpackHandler!(XmlDocument, xmlUnpackHandler);\n\n    /// Now we can serialize/deserialize XmlDocument object instances via a\n    /// base class reference.\n    Document doc = new XmlDocument(\"test.xml\");\n    auto data = pack(doc);\n    XmlDocument xml = unpack!XmlDocument(data);\n    assert(xml.name == \"test.xml\");  // xml.name is \"test.xml\"\n}\n```\n\nIn addition, here is also a method using `@serializedAs` attribute:\n\n```d\nimport std.datetime: Clock, SysTime;\nstatic struct SysTimePackProxy\n{\n    static void serialize(ref Packer p, ref in SysTime tim)\n    {\n        p.pack(tim.toISOExtString());\n    }\n\n    static void deserialize(ref Unpacker u, ref SysTime tim)\n    {\n        string tmp;\n        u.unpack(tmp);\n        tim = SysTime.fromISOExtString(tmp);\n    }\n}\nstatic struct LogData\n{\n    string msg;\n    string file;\n    ulong  line;\n    @serializedAs!SysTimePackProxy SysTime timestamp;\n\n    this(string message, string file = __FILE__, ulong line = __LINE__)\n    {\n        this.msg = message;\n        this.file = file;\n        this.line = line;\n        this.timestamp = Clock.currTime();\n    }\n}\n\nvoid main()\n{\n    /// Now we can serialize/deserialize LogData\n    LogData[] logs;\n    logs ~= LogData(\"MessagePack is nice!\");\n    auto data = pack(logs);\n    LogData[] datas = unpack!(LogData[])(data);\n    assert(datas[0].timestamp.toString() == datas[0].timestamp.toString());\n}\n```\n\n## The PackerImpl / Unpacker / StreamingUnpacker types\n\nThese types are used by the `pack` and `unpack` functions.\n\nSee the documentation of [PackerImpl](http://msgpack.github.io/msgpack-d/#PackerImpl), [Unpacker](http://msgpack.github.io/msgpack-d/#Unpacker) and [StreamingUnpacker](http://msgpack.github.io/msgpack-d/#StreamingUnpacker) for more details.\n\n# Links\n\n* [The MessagePack Project](http://msgpack.org/)\n\n  The official MessagePack protocol website.\n\n* [msgpack-d's issue tracker](https://github.com/msgpack/msgpack-d/issues)\n\n  Use this issue tracker to review and file bugs in msgpack-d.\n\n* [MessagePack's Github](http://github.com/msgpack/)\n\n  Other language bindings and implementations of the msgpack protocol can be found here.\n\n# Copyright\n\n    Copyright (c) 2010- Masahiro Nakagawa\n\n# License\n\nDistributed under the [Boost Software License, Version 1.0](http://www.boost.org/users/license.html).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsgpack%2Fmsgpack-d","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsgpack%2Fmsgpack-d","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsgpack%2Fmsgpack-d/lists"}