-
Notifications
You must be signed in to change notification settings - Fork 59
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
v2: UUID unmarshal bug #211
Comments
fixed by using build tag "go_tarantool_msgpack_v5" |
Thank you for the issue! The problem is relevant for msgpack.v2, the reason probably in that line: Line 46 in bda4442
It looks like it doesn't move a pointer to unreaded data in the decoder buffer. The problem should be fixed with Marshaler/Unmarshaler interface (see the decimal implementation) insead of encodeUUID/decodeUUID. go-tarantool/decimal/decimal.go Line 59 in bda4442
go-tarantool/decimal/decimal.go Line 80 in bda4442
A test to reproduce (I will improve it later): --- a/uuid/uuid_test.go
+++ b/uuid/uuid_test.go
@@ -8,6 +8,7 @@ import (
"time"
"github.com/google/uuid"
+ "gopkg.in/vmihailenco/msgpack.v2"
. "github.com/tarantool/go-tarantool"
"github.com/tarantool/go-tarantool/test_helpers"
_ "github.com/tarantool/go-tarantool/uuid"
@@ -133,6 +134,30 @@ func TestReplace(t *testing.T) {
tupleValueIsId(t, respSel.Data, id)
}
+type TestMarshalTuple struct {
+ UUID uuid.UUID `json:"uuid" msgpack:"uuid"`
+ Name string `json:"name" msgpack:"name"`
+}
+
+func TestMatshal(t *testing.T) {
+ space := TestMarshalTuple{UUID: uuid.New(), Name: "foo bar"}
+ //space := TestMarshalTuple{UUID: "ololo", Name: "foo bar"}
+ b, err := msgpack.Marshal(&space)
+ if err != nil {
+ t.Fatalf("Unable to marshal: %s", err)
+ }
+
+ var item TestMarshalTuple
+ err = msgpack.Unmarshal(b, &item)
+ if err != nil {
+ t.Fatalf("Unable to unmarshal: %s", err)
+ }
+
+ if item.Name != space.Name {
+ t.Fatalf("names is not equal: %s != %s", space.Name, item.Name)
+ }
+}
+ |
The problem comes from the implementation of msgpack.v2. In the first case, we only get external data in the begginning of
In the second case (in the issue) we have (external id, external len, external data) in the beginning of
I see three ways:
go-tarantool/uuid/uuid_test.go Lines 35 to 50 in 460bf88
|
The test fails with msgpack.v2 [1]. 1. #211
The test fails with msgpack.v2 [1]. 1. #211
A commit with a test for the issue: |
Unfortunately, these are problems with We will do in the next major update of the connector. |
To solve the problem, a user need to use the build tag: |
I have that struct:
So I do simple marshal/unmarshal:
As you can see Name is empty after unmashalling, but It have to be "foo bar".
If I use https://github.com/citilinkru/uuid-msgpack the code above will work good and name will be "foo bar", but I can't combine both packages because of conflicts.
The text was updated successfully, but these errors were encountered: