-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected varbinary encoding #6
Comments
Hello @DifferentialOrange Uff - that was tricky! The reason is that msgpack v5 decodes types to smallest representation by default. It's not so handy so to mimic msgpack v2 behavior from official The rules for it from Msgpack v5 docs:
So So two approaches are possible to deal with this: type varbinary []byte
func (b *varbinary) DecodeMsgpack(d *msgpack.Decoder) error {
var err error
*b, err = d.DecodeBytes()
return err
}
type T struct {
Value varbinary
}
func TestVarbinary(t *testing.T) {
conn, err := Connect("127.0.0.1:3301", Opts{
User: "guest",
})
if err != nil {
t.Fatal(err)
}
// Way 1 - with decoding into interface.
resp, err := conn.Exec(Eval("return box.space.testvarbin:select{}", []interface{}{}))
if err != nil {
t.Fatal(err)
}
log.Println("Code", resp.Code)
// Slice bounds check skipped here to keep example short!
log.Println("Data", []byte(resp.Data[0].([]interface{})[0].([]interface{})[0].(string)))
// Way 2 - with decoding directly to varbinary.
var result [][]T
err = conn.ExecTyped(Eval("return box.space.testvarbin:select{}", []interface{}{}), &result)
log.Println("Error", err)
// Slice bounds check skipped here to keep example short!
log.Println("Data", result[0][0].Value)
} Output:
|
I suppose can be closed. |
I've met some unexpecting varbinary encoding results while comparing different Tarantool connectors. Since I'm not experienced in both Go and Tarantool-Go usage, there is a high possibility that something wrong with my test runs.
Let Tarantool be
tarantool/go-tarantool
Output is
viciious/go-tarantool
Output is
FZambia/tarantool
Output is
I'm not sure how to interpret this, but first two seems like they are ok with varbinary and the last one may have some issues.
The text was updated successfully, but these errors were encountered: