Comments (6)
Really, this is the correct format for DagJSON
(that is the JSON IPLD format). Unfortunately, our APIs don't use DagJSON
(they should but it's hard to fix that now).
We did the {"/": ...}
dance to add a new "primitive" type (the CID) to JSON.
In practice, this allows us to write:
type Person struct {
name string
friends map[string]cid.Cid
}
And have json.Marshal(somePerson)
spit out valid IPLD.
from go-cid.
@Stebalien that may be true, but now that we can put strings in maps how will map[cid.Cid]string
serialize since the key is a JSON object and not a string?
from go-cid.
It won't. That's not valid DagJSON. It could serialize to CBOR (in theory) but we currently restrict map keys to be strings (IIRC, this is a hold-over from the days when we wanted all map keys to be valid path components).
from go-cid.
Right my point is with the current serialization of a CID a map[cid.Cid]string
won't serialize to valid JSON. This could be a problem.....
EDIT: I didn't actually try this so let em write some quick test cases first....
from go-cid.
So after testing and a little more research it seams map[cid.Cid]string
won't serialize anyway. To fix this we would need to implement the encoding.TextMarshaler
and encoding.TextUnmarshaler
interface which just convert the Cid to string without a path comment.
from go-cid.
I was going to open an issue to discuss that { "/" : <cid> }
is quite weird and I think it's inconsistent in some places in the go-ipfs API how CIDs are presented. While correct in the IPLD context, it difficults using CIDs in non-IPLD contexts. CIDs are the core identifier for IPLD, but must they have a IPLD-based JSON output?
Note how this requires that every language implements additional json handling for CIDs just because it does not come as a simple string that can be thrown to Decode()
. It just becomes harder to work with CIDs and it's not obvious why things are as they are.
Would having a global switch (variable) that just outputs them as a string be an option? It's a bad solution, but I can't think of anything non-breaking and would help cluster keep API compatibility if we let Cids marshal themselves to JSON in the future.
from go-cid.
Related Issues (20)
- Implement 'K'-encoding (base36 cids) HOT 2
- Inaccurate godoc comment for uvarint HOT 1
- Possible to calculate cid using Writer interface instead of reading full file into memory? HOT 3
- add CidFromReader HOT 9
- cid Undef cannot be marshalled HOT 3
- Support parse (github.com/ipfs/go-path).Path HOT 16
- Provide an efficient API to check whether a CID has `IDENTITY` multihash code HOT 3
- CodecToStr and Codecs in v0.3.1 could cause data corruption HOT 3
- CidFromReader wraps valid io.EOF in ErrInvalidCid HOT 1
- Bloom filter backed version of Cid.Set HOT 1
- Extract non-core functionaly into new package HOT 5
- LRU cache HOT 3
- protobuf vs dag-pb HOT 2
- Generated CIDv0 differs from the one generated by IPFS HOT 13
- Proposal: Moving CID to multiformats Org HOT 1
- Prefix.Sum creates bad inline CIDs
- Qm hash identifiers duplicated within the IPFS ecosystem HOT 1
- Harden varint encoding. HOT 1
- Support for reading concatenated CIDs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-cid.