Simplify structure unmarshaling for SDK users #18

Closed
opened 2025-12-28 18:11:57 +00:00 by sami · 1 comment
Owner

Originally created by @alexvanin on GitHub (Oct 9, 2020).

There is an straightforward way to serialize SDK structure by converting it into unified structure and then using stable marshaler on it.

data, err := bearerToken.ToV2().StableMarshal(nil)

But there is not simple way to convert it back. To do that, user has to use transport structure even though it is not necessary, because unified structures are matched with protobuf definition.

grpcToken := new(grpcACL.BearerToken)
err = grpcToken.Unmarshal(data)  // we can omit that

v2Token := v2ACL.BearerTokenFromGRPCMessage(grpcToken)
bearerToken := token.NewBearerTokenFromV2(v2Token)

The issue is that unlike stable marshallers, unmarshallers are a little more complicated. And we don't have to make them stable (with strict field order check in binary message) at all. Can we just hide GRPC or any other transport layer behind Unmarshal() function in v2/* packages?

Originally created by @alexvanin on GitHub (Oct 9, 2020). There is an straightforward way to serialize SDK structure by converting it into unified structure and then using stable marshaler on it. ```go data, err := bearerToken.ToV2().StableMarshal(nil) ``` But there is not simple way to convert it back. To do that, user has to use transport structure even though it is not necessary, because unified structures are matched with protobuf definition. ```go grpcToken := new(grpcACL.BearerToken) err = grpcToken.Unmarshal(data) // we can omit that v2Token := v2ACL.BearerTokenFromGRPCMessage(grpcToken) bearerToken := token.NewBearerTokenFromV2(v2Token) ``` The issue is that unlike stable marshallers, unmarshallers are a little more complicated. And we don't have to make them stable (with strict field order check in binary message) at all. Can we just hide GRPC or any other transport layer behind `Unmarshal()` function in `v2/*` packages?
sami 2025-12-28 18:11:57 +00:00
Author
Owner

@cthulhu-rider commented on GitHub (Oct 23, 2020):

I think we can. Here is an example. We can disseminate this approach to all v2 messages. StableUnmarshal can be renamed to Unmarshal (or UnmarshalBinary to implement encoding.BinaryUnmarshaler).

@cthulhu-rider commented on GitHub (Oct 23, 2020): I think we can. [Here](https://github.com/nspcc-dev/neofs-api-go/blob/ad0b01e892dd4d8a9b4c92082caece27d5663462/v2/refs/marshal.go#L145) is an example. We can disseminate this approach to all `v2` messages. `StableUnmarshal` can be renamed to `Unmarshal` (or `UnmarshalBinary` to implement `encoding.BinaryUnmarshaler`).
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-api-go#18
No description provided.