From 1d2420323ca555f8ac45969bd39415c5e619e4e0 Mon Sep 17 00:00:00 2001 From: Péter Szilágyi Date: Thu, 13 Aug 2015 11:12:38 +0300 Subject: rlp: add support for boolean encoding/decoding --- rlp/encode.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'rlp/encode.go') diff --git a/rlp/encode.go b/rlp/encode.go index 0ddef7bbb..b525ae4e7 100644 --- a/rlp/encode.go +++ b/rlp/encode.go @@ -361,6 +361,8 @@ func makeWriter(typ reflect.Type) (writer, error) { return writeBigIntNoPtr, nil case isUint(kind): return writeUint, nil + case kind == reflect.Bool: + return writeBool, nil case kind == reflect.String: return writeString, nil case kind == reflect.Slice && isByte(typ.Elem()): @@ -398,6 +400,15 @@ func writeUint(val reflect.Value, w *encbuf) error { return nil } +func writeBool(val reflect.Value, w *encbuf) error { + if val.Bool() { + w.str = append(w.str, 0x01) + } else { + w.str = append(w.str, 0x80) + } + return nil +} + func writeBigIntPtr(val reflect.Value, w *encbuf) error { ptr := val.Interface().(*big.Int) if ptr == nil { -- cgit