Skip to content

Add Validation in canoto.Marshal #119

Description

@RodrigoVillar

Referencing #117, it's possible for canoto.Unmarshal() to fail even if canoto.Marshal() works. An example is as follows:

type Foo struct {
    Bar []byte `canoto:"bytes,1"`

    canotoData canotoData_Foo
}

anyField := canoto.AnyField{
    Name: "Bar",
    Bar: []byte{},
}

a := canoto.Any{
    Fields: []canoto.AnyField{anyField},
}

f := &Foo{}
spec := f.CanotoSpec()

b, err := canoto.Marshal(spec, a) // err == nil

bytes, err := canoto.Unmarshal(spec, b) // err != nil

Ideally, we should have that:

canoto.Unmarshal(spec, canoto.Marshal(spec, a)) // ignoring errs

Adding a verification step to canoto.Marshal() would allow for the above to be possible.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions