{"id":31959031,"url":"https://github.com/edjcase/motoko_dag_pb","last_synced_at":"2026-02-17T23:03:12.174Z","repository":{"id":307182298,"uuid":"1021071732","full_name":"edjCase/motoko_dag_pb","owner":"edjCase","description":"A motoko library to encode/decode DAG Protobuf bytes","archived":false,"fork":false,"pushed_at":"2025-09-06T21:02:44.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-14T15:19:17.329Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Motoko","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/edjCase.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":"2025-07-16T20:48:26.000Z","updated_at":"2025-09-06T21:02:48.000Z","dependencies_parsed_at":"2025-07-29T23:00:00.748Z","dependency_job_id":"24772d47-f84b-46c5-b918-244a97b7f4ef","html_url":"https://github.com/edjCase/motoko_dag_pb","commit_stats":null,"previous_names":["edjcase/motoko_dag_pb"],"tags_count":0,"template":false,"template_full_name":"edjCase/motoko-library-template","purl":"pkg:github/edjCase/motoko_dag_pb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_dag_pb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_dag_pb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_dag_pb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_dag_pb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edjCase","download_url":"https://codeload.github.com/edjCase/motoko_dag_pb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_dag_pb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29561783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T21:50:49.831Z","status":"ssl_error","status_checked_at":"2026-02-17T21:46:15.313Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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-10-14T15:18:34.166Z","updated_at":"2026-02-17T23:03:12.159Z","avatar_url":"https://github.com/edjCase.png","language":"Motoko","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Motoko DAG-PB\n\n[![MOPS](https://img.shields.io/badge/MOPS-dag--pb-blue)](https://mops.one/dag-pb)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/yourusername/motoko_dag_pb/blob/main/LICENSE)\n\nA Motoko implementation of DAG-PB (DAG-Protobuf) for encoding and decoding IPLD data structures with content addressing support.\n\n## Package\n\n### MOPS\n\n```bash\nmops add dag-pb\n```\n\nTo set up MOPS package manager, follow the instructions from the [MOPS Site](https://mops.one)\n\n## What is DAG-PB?\n\nDAG-PB is a protobuf-based format used by IPFS for representing file system data. It's the primary format for UnixFS, enabling content-addressed storage of files and directories. DAG-PB nodes contain data and links to other nodes, forming a directed acyclic graph (DAG).\n\n## Quick Start\n\n### Example 1: Basic Encoding\n\n```motoko\nimport DagPb \"mo:dag-pb\";\nimport CID \"mo:cid\";\nimport Runetime \"mo:core/Runetime\";\n\n// Create a simple DAG-PB node with data\nlet node : DagPb.Node = {\n   links = [\n       {\n           hash = bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi;\n           name = ?\"config.json\";\n           tsize = ?256;\n       },\n       {\n           hash = bafybeihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku;\n           name = ?\"data.csv\";\n           tsize = ?4096;\n       }\n   ];\n   data = null; // Optional Blob data\n};\n\n// Encode to bytes\nlet bytes: [Nat8] = switch (DagPb.toBytes(node)) {\n    case (#err(error)) Runetime.trap(\"Encoding failed: \" # debug_show(error));\n    case (#ok(bytes)) bytes;\n};\n```\n\n### Example 2: Basic Decoding\n\n```motoko\nimport DagPb \"mo:dag-pb\";\nimport CID \"mo:cid\";\n\nlet bytes : Blob = \"...\"; // DAG-PB bytes\n\n// Decode to node\nlet dagNode : DagPb.Node = switch (DagPb.fromBytes(bytes.vals())) {\n    case (#err(error)) Runetime.trap(\"Decoding failed: \" # debug_show(error));\n    case (#ok(node)) node;\n};\n```\n\n### Example 3: Buffer-based Encoding\n\n```motoko\nimport DagPb \"mo:dag-pb\";\nimport Buffer \"mo:buffer\";\nimport List \"mo:core/List\";\n\nlet node : DagPb.Node = ...;\n\n// Create buffer for streaming encoding\nlet list = List.empty\u003cNat8\u003e();\n\n// Encode to buffer and get bytes written count\nlet bytesWritten: Nat = switch (DagPb.toBytesBuffer(Buffer.fromList\u003cNat8\u003e(list), node)) {\n    case (#err(error)) Debug.trap(\"Encoding failed: \" # debug_show(error));\n    case (#ok(count)) count;\n};\n\n// Buffer now contains the encoded protobuf data\nlet encodedBytes = List.toArray(list);\n```\n\n## API Reference\n\n### Main Functions\n\n- **`toBytes()`** - Converts DAG-PB nodes to binary protobuf format\n- **`fromBytes()`** - Converts binary protobuf data back to DAG-PB nodes\n- **`toBytesBuffer()`** - Streams encoding to a buffer and returns bytes written count\n\n### Types\n\n```motoko\n// Main node type representing a DAG-PB node\npublic type Node = {\n    data : ?[Nat8];    // Optional raw data payload\n    links : [Link];    // Array of links to other nodes\n};\n\n// Link to another DAG-PB node\npublic type Link = {\n    hash : CID.CID;    // CID of the linked node\n    name : ?Text;      // Optional name for the link\n    tsize : ?Nat;      // Optional total size of linked subtree\n};\n```\n\n### Functions\n\n```motoko\n// Encode a DAG-PB node to bytes\npublic func toBytes(node : Node) : Result.Result\u003c[Nat8], Text\u003e;\n\n// Encode a DAG-PB node to an existing buffer (returns bytes written count)\npublic func toBytesBuffer(buffer : Buffer.Buffer\u003cNat8\u003e, node : Node) : Result.Result\u003cNat, Text\u003e;\n\n// Decode bytes to a DAG-PB node\npublic func fromBytes(bytes : Iter.Iter\u003cNat8\u003e) : Result.Result\u003cNode, Text\u003e;\n```\n\n## DAG-PB Specification\n\nThis implementation follows the official IPFS DAG-PB specification:\n[https://ipld.io/specs/codecs/dag-pb/spec/](https://ipld.io/specs/codecs/dag-pb/spec/)\n\n### Protobuf Schema\n\n```protobuf\nmessage PBLink {\n  // binary CID (with no multibase prefix) of the target object\n  optional bytes Hash = 1;\n\n  // UTF-8 string name\n  optional string Name = 2;\n\n  // cumulative size of target object\n  optional uint64 Tsize = 3;\n}\n\nmessage PBNode {\n  // refs to other objects\n  repeated PBLink Links = 2;\n\n  // opaque user data\n  optional bytes Data = 1;\n}\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedjcase%2Fmotoko_dag_pb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedjcase%2Fmotoko_dag_pb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedjcase%2Fmotoko_dag_pb/lists"}