Skip to content

Commit

Permalink
Merge pull request #41 from ipfs/feat/atlas-tweaks
Browse files Browse the repository at this point in the history
import changes from the filecoin branch
  • Loading branch information
Stebalien authored Sep 24, 2018
2 parents 2e6de03 + 3b7067b commit b7e8f2b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions refmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ var cidAtlasEntry = atlas.BuildEntry(cid.Cid{}).
)).
Complete()

var bigIntAtlasEntry = atlas.BuildEntry(big.Int{}).Transform().
// BigIntAtlasEntry gives a reasonable default encoding for big.Int. It is not
// included in the entries by default.
var BigIntAtlasEntry = atlas.BuildEntry(big.Int{}).Transform().
TransformMarshal(atlas.MakeMarshalTransformFunc(
func(i big.Int) ([]byte, error) {
return i.Bytes(), nil
Expand All @@ -33,9 +35,10 @@ var bigIntAtlasEntry = atlas.BuildEntry(big.Int{}).Transform().
})).
Complete()

var cborAtlas atlas.Atlas
// CborAtlas is the refmt.Atlas used by the CBOR IPLD decoder/encoder.
var CborAtlas atlas.Atlas
var cborSortingMode = atlas.KeySortMode_RFC7049
var atlasEntries = []*atlas.AtlasEntry{cidAtlasEntry, bigIntAtlasEntry}
var atlasEntries = []*atlas.AtlasEntry{cidAtlasEntry}

var (
cloner encoding.PooledCloner
Expand All @@ -48,12 +51,12 @@ func init() {
}

func rebuildAtlas() {
cborAtlas = atlas.MustBuild(atlasEntries...).
WithMapMorphism(atlas.MapMorphism{atlas.KeySortMode_RFC7049})
CborAtlas = atlas.MustBuild(atlasEntries...).
WithMapMorphism(atlas.MapMorphism{KeySortMode: atlas.KeySortMode_RFC7049})

marshaller = encoding.NewPooledMarshaller(cborAtlas)
unmarshaller = encoding.NewPooledUnmarshaller(cborAtlas)
cloner = encoding.NewPooledCloner(cborAtlas)
marshaller = encoding.NewPooledMarshaller(CborAtlas)
unmarshaller = encoding.NewPooledUnmarshaller(CborAtlas)
cloner = encoding.NewPooledCloner(CborAtlas)
}

// RegisterCborType allows to register a custom cbor type
Expand Down

0 comments on commit b7e8f2b

Please sign in to comment.