rlp: add support for boolean encoding/decoding

This commit is contained in:
Péter Szilágyi
2015-08-13 11:12:38 +03:00
parent 0dd6911c62
commit 1d2420323c
4 changed files with 53 additions and 0 deletions

View File

@ -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 {