Skip to content

Commit

Permalink
fixup! feat: introduce UIntNode interface, used within DAG-CBOR codec
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jun 8, 2022
1 parent 5585719 commit 633915c
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions codec/dagcbor/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,20 @@ func marshal(n datamodel.Node, tk *tok.Token, sink shared.TokenSink, options Enc
_, err = sink.Step(tk)
return err
case datamodel.Kind_Int:
var v uint64
positive := true
if uin, ok := n.(datamodel.UintNode); ok {
var err error
v, err = uin.AsUint()
v, err := uin.AsUint()
if err != nil {
return err
}
tk.Type = tok.TUint
tk.Uint = v
} else {
i, err := n.AsInt()
v, err := n.AsInt()
if err != nil {
return err
}
sign := (i >> 63)
v = uint64((i ^ sign) - sign)
positive = sign == 0
}
if positive {
tk.Type = tok.TUint
tk.Uint = v
} else {
tk.Type = tok.TInt
tk.Int = -int64(v)
tk.Int = v
}
_, err := sink.Step(tk)
return err
Expand Down

0 comments on commit 633915c

Please sign in to comment.