Skip to content

Commit 5e5f3ba

Browse files
committed
Merge pull request #37 from ipfs/ipld-spec
WIP: IPLD spec
2 parents 1a17d32 + fc38955 commit 5e5f3ba

File tree

2 files changed

+625
-0
lines changed

2 files changed

+625
-0
lines changed

merkledag/ipld-compat-protobuf.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# IPLD conversion with Protocol Buffer legacy IPFS node format
2+
3+
IPLD has a known conversion with the legacy Protocol Buffers format in order for new IPLD objects to interact with older protocol buffer objects.
4+
5+
## Detecting the format in use
6+
7+
The format is encapsulated after two multicodec headers. The first have the codec path `/mdagv1` and can be used to detect whether IPLD objects are transmitted or just legacy protocol buffer messages.
8+
9+
The second multicodec header is used to detect the actual format in which the IPLD object is encoded:
10+
11+
- `/protobuf/msgio`: is the encapsulation for protocol buffer message
12+
- `/json`: is the encapsulation for JSON encoding
13+
- `/cbor`: is the encapsulation for CBOR encoding
14+
15+
For example, a protocol buffer object encapsulated in a multicodec header would start with "`\x08/mdagv1\n\x10/protobuf/msgio\n`" corresponding to the bytes :
16+
17+
08 2f 6d 64 61 67 76 31 0a
18+
10 2f 70 72 6f 74 6f 62 75 66 2f 6d 73 67 69 6f 0a
19+
20+
A JSON encoded object would start with "`\x08/mdagv1\n\x06/json\n`" and a CBOR encoded object would start with "`\x08/mdagv1\n\x06/cbor\n`".
21+
22+
23+
## Description of the legacy protocol buffers format
24+
25+
This format is defined with the Protocol Buffers syntax as:
26+
27+
message PBLink {
28+
optional bytes Hash = 1;
29+
optional string Name = 2;
30+
optional uint64 Tsize = 3;
31+
}
32+
33+
message PBNode {
34+
repeated PBLink Links = 2;
35+
optional bytes Data = 1;
36+
}
37+
38+
## Conversion to IPLD model
39+
40+
The conversion to the IPLD data model MUST be convertible back to protocol buffers, resulting in an identical byte stream (so the hash corresponds). This implies that ordering and duplicate links must be preserved in some way. As such, they are stored in an array and not in a map indexed by their name.
41+
42+
There is a canonical form which is described below:
43+
44+
{
45+
"data": "<Data>",
46+
"links": [
47+
{
48+
"@link": "/ipfs/<Links[0].Hash.(base58)>",
49+
"name": "<Links[0].Name>",
50+
"size": <Links[0].Tsize>
51+
},
52+
{
53+
"@link": "/ipfs/<Links[1].Hash.(base58)>",
54+
"name": "<Link[1].Name>",
55+
"size": <Links[1].Tsize>
56+
},
57+
{
58+
"@link": "/ipfs/<Links[2].Hash.(base58)>",
59+
"name": "<Links[2].Name>",
60+
"size": <Links[2].Tsize>
61+
},
62+
...
63+
]
64+
}
65+
66+
The main object contains:
67+
68+
- A `data` key containing the binary data string
69+
- A `links` array containing links in the correct order
70+
71+
Each link consists of:
72+
73+
- A `@link` key containing the path to the destination document (Using the `/ipfs/` prefix)
74+
- A `name` key containing the link name (a text string)
75+
- A `size` unsigned integer containing the link size as stored in the Protocol Buffer object
76+
77+
Implementations are free to add any other top level key they need. In particular it may be interesting to access the links indexed by their name. This is a purely optional feature and additional keys cannot possibly be encoded back to the protonal Protocol Buffer format.

0 commit comments

Comments
 (0)