Skip to content

Commit

Permalink
add format & parse int to bool
Browse files Browse the repository at this point in the history
  • Loading branch information
khorevaa committed Sep 16, 2021
1 parent a47f0b9 commit 1abbc5d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ras/codec256/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,18 @@ func ParseInt(r io.Reader, into interface{}) error {
*typed = uint64(val)
case *int64:
*typed = int64(val)
case bool:
typed = false
if val == 1 {
typed = true
}
case *bool:
*typed = false
if val == 1 {
*typed = true
}
default:
return &ParseError{"uint32",
return &ParseError{"int32",
fmt.Sprintf("convert to <%s> unsupporsed", reflect.TypeOf(typed))}
}
return nil
Expand Down
10 changes: 10 additions & 0 deletions ras/codec256/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ func FormatInt(w io.Writer, value interface{}) error {
val = uint32(*tVal)
case *uint32:
val = uint32(*tVal)
case bool:
val = uint32(0)
if tVal {
val = uint32(1)
}
case *bool:
val = uint32(0)
if *tVal {
val = uint32(1)
}
default:
return &TypeEncoderError{"int", "TODO"}
}
Expand Down

0 comments on commit 1abbc5d

Please sign in to comment.