Think about ReadFrom/WriteToV2 one more time #205

Open
opened 2025-12-28 18:07:25 +00:00 by sami · 5 comments
Owner

Originally created by @carpawell on GitHub (Nov 15, 2023).

Problem

With ReadFromV2 it mostly always required more lines of code to achieve the same thing with ToV2 and FromV2 that allocate structs inside. We can think about some helpers placed near the methods.

Context

Updating SDK in some old code or writing a new code can be annoying with these totally necessary lines (when there is no need to reuse struct b/w reading or writing protocol conversions). This approach was presented in https://github.com/nspcc-dev/neofs-sdk-go/pull/170 and we had some long discussions, it was not an easy change.

Originally created by @carpawell on GitHub (Nov 15, 2023). ## Problem With `ReadFromV2` it mostly always required more lines of code to achieve the same thing with `ToV2` and `FromV2` that allocate structs inside. We can think about some helpers placed near the methods. ## Context Updating SDK in some old code or writing a new code can be annoying with these totally necessary lines (when there is no need to reuse struct b/w reading or writing protocol conversions). This approach was presented in https://github.com/nspcc-dev/neofs-sdk-go/pull/170 and we had some long discussions, it was not an easy change.
Author
Owner

@cthulhu-rider commented on GitHub (Nov 24, 2023):

normally conversion to and from message to SDK entities should be done in exactly one place: https://pkg.go.dev/github.com/nspcc-dev/neofs-sdk-go/client and https://pkg.go.dev/github.com/nspcc-dev/neofs-node@v0.38.1/pkg/network/transport respectively. V2-converters accidentally went beyond these two spaces of the system, so you are experiencing a headache

@cthulhu-rider commented on GitHub (Nov 24, 2023): normally conversion to and from message to SDK entities should be done in exactly one place: https://pkg.go.dev/github.com/nspcc-dev/neofs-sdk-go/client and https://pkg.go.dev/github.com/nspcc-dev/neofs-node@v0.38.1/pkg/network/transport respectively. V2-converters accidentally went beyond these two spaces of the system, so you are experiencing a headache * keep an eye on https://github.com/nspcc-dev/neofs-api-go/issues/395
Author
Owner

@carpawell commented on GitHub (Nov 24, 2023):

It does not matter if I need to use it in a single package or in a dozen packages, if I write tests, or if I am a regular SDK user. I just do it sometimes. The same way I encode cID and oID and maybe some other things that I forget about now. I just need more lines of (boilerplate) code for no reason (usually).

keep an eye on https://github.com/nspcc-dev/neofs-api-go/issues/395

How can this help me?

@carpawell commented on GitHub (Nov 24, 2023): It does not matter if I need to use it in a single package or in a dozen packages, if I write tests, or if I am a regular SDK user. I just do it sometimes. The same way I encode cID and oID and maybe some other things that I forget about now. I just need more lines of (boilerplate) code for no reason (usually). > keep an eye on https://github.com/nspcc-dev/neofs-api-go/issues/395 How can this help me?
Author
Owner

@cthulhu-rider commented on GitHub (Dec 4, 2023):

@carpawell, u've not described the exact problem yet in form: i want this but the only way is to cast into v2. If u have the case, report it

if u have some useful helpers, just propose it in PR or create an enhancement issue

@cthulhu-rider commented on GitHub (Dec 4, 2023): @carpawell, u've not described the exact problem yet in form: i want this but the only way is to cast into v2. If u have the case, report it if u have some useful helpers, just propose it in PR or create an enhancement issue
Author
Owner

@carpawell commented on GitHub (Dec 4, 2023):

If u have the case, report it

Why do we need cases for exported methods in the "SDK" repo? We already have them (methods) and we are not gonna delete them. Why do I need this? Why this file has to have refs package imported now? Why do i have to explicitly create a var to fill it in go?

in form: i want this but the only way is to cast into v2

The same way I have to encode/decode addresses, IDs, etc. Why? That is not about V2 only.

create an enhancement issue

We are discussing such an issue right now.

@carpawell commented on GitHub (Dec 4, 2023): > If u have the case, report it Why do we need cases for exported methods in the "SDK" repo? We already have them (methods) and we are not gonna delete them. Why do I need [this](https://github.com/nspcc-dev/neofs-node/blob/78823a3b5a037a59d5ef41ef1be9bc177c175b25/pkg/services/container/morph/executor.go#L90-L91)? Why this file has to have `refs` package imported now? Why do i have to explicitly create a var to fill it in _go_? > in form: i want this but the only way is to cast into v2 The same way I have to encode/decode addresses, IDs, etc. Why? That is not about V2 only. > create an enhancement issue We are discussing such an issue right now.
Author
Owner

@roman-khimov commented on GitHub (Dec 6, 2023):

ReadFrom is supposed to be more efficient in some cases (preallocated things, you know it). In practice we have a lot of cases where we do not have anything preallocated. Additional NewFromV2 could be helpful to drop some repetitive code.

@roman-khimov commented on GitHub (Dec 6, 2023): `ReadFrom` is supposed to be more efficient in some cases (preallocated things, you know it). In practice we have a lot of cases where we do not have anything preallocated. _Additional_ `NewFromV2` could be helpful to drop some repetitive code.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nspcc-dev/neofs-sdk-go#205
No description provided.