apache / dubbo-go-hessian2

caucho hessian2 implementation in Go for [apache/dubbo-go](https://github.com/apache/dubbo-go) which is compatible with [dubbo-hessian-lite](https://github.com/apache/dubbo-hessian-lite)
Apache License 2.0
209 stars 113 forks source link

empty map write null but BC_MAP_UNTYPED+BC_END expected #274

Closed zhwaaaaaa closed 3 years ago

zhwaaaaaa commented 3 years ago

v1.9.2 map.go line 120. null is not expected. instead of empty map (BC_MAP_UNTYPED+BC_END) ` keys = value.MapKeys() if len(keys) == 0 { // fix: set nil for empty map e.buffer = EncNull(e.buffer) return nil }

typ = value.Type().Key()
e.buffer = encByte(e.buffer, BC_MAP_UNTYPED)
for i := 0; i < len(keys); i++ {
    k, err = getMapKey(keys[i], typ)
    if err != nil {
        return perrors.Wrapf(err, "getMapKey(idx:%d, key:%+v)", i, keys[i])
    }
    if err = e.Encode(k); err != nil {
        return perrors.Wrapf(err, "failed to encode map key(idx:%d, key:%+v)", i, keys[i])
    }
    entryValueObj := value.MapIndex(keys[i]).Interface()
    if err = e.Encode(entryValueObj); err != nil {
        return perrors.Wrapf(err, "failed to encode map value(idx:%d, key:%+v, value:%+v)", i, k, entryValueObj)
    }
}
e.buffer = encByte(e.buffer, BC_END)`
wongoo commented 3 years ago

@zhwaaaaaa do u mean hessian2 should write Null for empty map, but now it get BC_MAP_UNTYPED+BC_END?

zhwaaaaaa commented 3 years ago

now get null for empty map. but BC_MAP_UNTYPED+BC_END expected

wongoo commented 3 years ago

@zhwaaaaaa u r correct, can u submit a PR for it?

zhwaaaaaa commented 3 years ago

ok