Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect cbor-gen #98

Merged
merged 1 commit into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
xerrors "golang.org/x/xerrors"
)

//go:generate cbor-gen-for --map-encoding Item

// Item is a single link traversed in a repsonse
type Item struct {
Link cid.Cid
Expand Down
22 changes: 10 additions & 12 deletions metadata/metadata_cbor_gen.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.

package metadata

import (
Expand All @@ -24,14 +22,14 @@ func (t *Item) MarshalCBOR(w io.Writer) error {
scratch := make([]byte, 9)

// t.Link (cid.Cid) (struct)
if len("Link") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"Link\" was too long")
if len("link") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"link\" was too long")
}

if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Link"))); err != nil {
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("link"))); err != nil {
return err
}
if _, err := io.WriteString(w, "Link"); err != nil {
if _, err := io.WriteString(w, "link"); err != nil {
return err
}

Expand All @@ -40,14 +38,14 @@ func (t *Item) MarshalCBOR(w io.Writer) error {
}

// t.BlockPresent (bool) (bool)
if len("BlockPresent") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"BlockPresent\" was too long")
if len("blockPresent") > cbg.MaxLength {
return xerrors.Errorf("Value in field \"blockPresent\" was too long")
}

if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("BlockPresent"))); err != nil {
if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("blockPresent"))); err != nil {
return err
}
if _, err := io.WriteString(w, "BlockPresent"); err != nil {
if _, err := io.WriteString(w, "blockPresent"); err != nil {
return err
}

Expand Down Expand Up @@ -91,7 +89,7 @@ func (t *Item) UnmarshalCBOR(r io.Reader) error {

switch name {
// t.Link (cid.Cid) (struct)
case "Link":
case "link":

{

Expand All @@ -104,7 +102,7 @@ func (t *Item) UnmarshalCBOR(r io.Reader) error {

}
// t.BlockPresent (bool) (bool)
case "BlockPresent":
case "blockPresent":

maj, extra, err = cbg.CborReadHeaderBuf(br, scratch)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func TestDecodeEncodeMetadata(t *testing.T) {
blockPresent := rand.Int31()%2 == 0
initialMetadata = append(initialMetadata, Item{k, blockPresent})
fla.AssembleValue().CreateMap(2, func(fma fluent.MapAssembler) {
fma.AssembleEntry("Link").AssignLink(cidlink.Link{Cid: k})
fma.AssembleEntry("BlockPresent").AssignBool(blockPresent)
fma.AssembleEntry("link").AssignLink(cidlink.Link{Cid: k})
fma.AssembleEntry("blockPresent").AssignBool(blockPresent)
})
}
})
Expand Down