Skip to content
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

Cant GetTyped if one of tarantool response keys is non-string typed #368

Closed
KaymeKaydex opened this issue Jan 2, 2024 · 4 comments
Closed
Labels
wontfix This will not be worked on

Comments

@KaymeKaydex
Copy link

KaymeKaydex commented Jan 2, 2024

msgpack: invalid code=1 decoding string/bytes length

https://github.com/vmihailenco/msgpack/blob/19c91dfdfa062658c39d9321be26163fc5833bd1/decode_string.go#L31

@KaymeKaydex KaymeKaydex changed the title Cant GetTyped if one of keys is non-string typed Cant GetTyped if one of tarantool response keys is non-string typed Jan 2, 2024
@KaymeKaydex
Copy link
Author

Снимок экрана 2024-01-02 в 22 05 34 but data non-empty

@oleg-jukovec
Copy link
Collaborator

oleg-jukovec commented Jan 3, 2024

Please give an example of the code in which you decode the response with GetTyped() and the response decoded as {}interface with Get().

Ideally I would like to see a minimal reproducer.

Now it’s not entirely clear to me what’s not working for you.

@oleg-jukovec oleg-jukovec added the needs feedback Something is unclear with the issue label Jan 3, 2024
@oleg-jukovec
Copy link
Collaborator

oleg-jukovec commented Jan 3, 2024

I got it. You need to write a custom decoder for this cases, as example:

type testReproducer368 struct {
	Value int
	Foo   string
}

func (t *testReproducer368) DecodeMsgpack(d *msgpack.Decoder) error {
	var (
		err error
		l   int
	)
	if l, err = d.DecodeMapLen(); err != nil {
		return err
	}
	for i := 0; i < l; i++ {
		key, err := d.DecodeInterface()
		if err != nil {
			return err
		}
		value, err := d.DecodeInterface()
		if err != nil {
			return err
		}
		switch key {
		case int8(34):
			t.Value = int(value.(int8))
		case "foo":
			t.Foo = value.(string)
		}
	}
	return nil
}

func TestReproducer368(t *testing.T) {
	conn := test_helpers.ConnectWithValidation(t, dialer, opts)
	defer conn.Close()

	test := []testReproducer368{}
	err := conn.Do(NewEvalRequest("return {[34] = 2, foo = 'bar'}")).GetTyped(&test)
	require.NoError(t, err)
	require.Equal(t, []testReproducer368{testReproducer368{2, "bar"}}, test)
}

You could see examples of the custom decoders in the connector code or in the msgpack library. See:
vmihailenco/msgpack#314

@oleg-jukovec oleg-jukovec removed the needs feedback Something is unclear with the issue label Jan 3, 2024
@oleg-jukovec oleg-jukovec reopened this Jan 3, 2024
@oleg-jukovec oleg-jukovec added the needs feedback Something is unclear with the issue label Jan 3, 2024
@oleg-jukovec oleg-jukovec added wontfix This will not be worked on and removed needs feedback Something is unclear with the issue labels Jan 30, 2024
@oleg-jukovec
Copy link
Collaborator

The reason in the msgpack library implementation, we can't fix it on our side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants