-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/rebind-typed-node
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package json | ||
|
||
import ( | ||
"github.com/ipld/go-ipld-prime" | ||
"github.com/ipld/go-ipld-prime/codec/dagjson" | ||
"github.com/ipld/go-ipld-prime/schema" | ||
) | ||
|
||
const Code = 0x0129 | ||
|
||
type codec struct{} | ||
|
||
func (codec) Code() uint64 { | ||
return Code | ||
} | ||
|
||
func (codec) Encode(val any, typ schema.Type) ([]byte, error) { | ||
return Encode(val, typ) | ||
} | ||
|
||
func (codec) Decode(b []byte, bind any, typ schema.Type) error { | ||
return Decode(b, bind, typ) | ||
} | ||
|
||
var Codec = codec{} | ||
|
||
func Encode(val any, typ schema.Type) ([]byte, error) { | ||
return ipld.Marshal(dagjson.Encode, val, typ) | ||
} | ||
|
||
func Decode(b []byte, bind any, typ schema.Type) error { | ||
_, err := ipld.Unmarshal(b, dagjson.Decode, bind, typ) | ||
return err | ||
} |