Added sim_txs draft

This commit is contained in:
Jae Kwon
2015-07-11 18:01:21 -07:00
parent 24acda1afc
commit 109a3c2dd3
13 changed files with 260 additions and 49 deletions

View File

@ -17,11 +17,15 @@ func ReadBinary(o interface{}, r io.Reader, n *int64, err *error) interface{} {
rv, rt := reflect.ValueOf(o), reflect.TypeOf(o)
if rv.Kind() == reflect.Ptr {
if rv.IsNil() {
rv = reflect.New(rt.Elem())
o = rv.Interface()
// This allows ReadBinaryObject() to return a nil pointer,
// if the value read is nil.
rvPtr := reflect.New(rt)
ReadBinaryPtr(rvPtr.Interface(), r, n, err)
return rvPtr.Elem().Interface()
} else {
readReflectBinary(rv, rt, Options{}, r, n, err)
return o
}
readReflectBinary(rv, rt, Options{}, r, n, err)
return o
} else {
ptrRv := reflect.New(rt)
readReflectBinary(ptrRv.Elem(), rt, Options{}, r, n, err)
@ -69,11 +73,15 @@ func ReadJSONObject(o interface{}, object interface{}, err *error) interface{} {
rv, rt := reflect.ValueOf(o), reflect.TypeOf(o)
if rv.Kind() == reflect.Ptr {
if rv.IsNil() {
rv = reflect.New(rt.Elem())
o = rv.Interface()
// This allows ReadJSONObject() to return a nil pointer
// if the value read is nil.
rvPtr := reflect.New(rt)
ReadJSONObjectPtr(rvPtr.Interface(), object, err)
return rvPtr.Elem().Interface()
} else {
readReflectJSON(rv, rt, object, err)
return o
}
readReflectJSON(rv, rt, object, err)
return o
} else {
ptrRv := reflect.New(rt)
readReflectJSON(ptrRv.Elem(), rt, object, err)