From 1abbc5d8a3469318c0308b232136422d90c5cc7c Mon Sep 17 00:00:00 2001 From: Aleksey Khorev Date: Thu, 16 Sep 2021 21:30:40 +0300 Subject: [PATCH] add format & parse int to bool --- ras/codec256/decode.go | 12 +++++++++++- ras/codec256/encode.go | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ras/codec256/decode.go b/ras/codec256/decode.go index d4894ff..da86420 100644 --- a/ras/codec256/decode.go +++ b/ras/codec256/decode.go @@ -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 diff --git a/ras/codec256/encode.go b/ras/codec256/encode.go index b827995..9bbd156 100644 --- a/ras/codec256/encode.go +++ b/ras/codec256/encode.go @@ -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"} }