vtprotobuf icon indicating copy to clipboard operation
vtprotobuf copied to clipboard

Per Msg/Field Features

Open kevinconaway opened this issue 3 years ago • 2 comments

👋

Are there any plans to support adding features per-msg or per-field?

For example, for some of our string or []byte fields, we prefer to unmarshal them as "unsafe" so as to avoid an allocation if we don't plan to keep the data in memory past the lifetime of the original message.

I was thinking that type of behavior could be added as an annotation in the proto, similar to how the extensions in gogo currently work.

Is that something that is 1.) feasible with this project 2.) something that you would be interested in?

If so, I could try to come up with a POC

Thanks

kevinconaway avatar Jul 01 '21 23:07 kevinconaway

Hello @kevinconaway! I think ultimately there are two things that may actually be decoupled:

  1. add support for unsafe casting of string and []byte fields;
  2. have per-message / per-field features.

I think (1) is definitely interesting, but I would be curious about use cases for (2). Could you provide some?

Typically, for (1), we could think of adding an unsafe feature providing unsafe methods to unmarshal messages, which doesn't need (2). This would affect all fields of the message, which should be OK, shouldn't it? Presumably, the lifetime for all fields of the message should be the same? In my mind at least, when using memory pooling for instance, we release bytes for the whole message at the same time, but I could be missing some other use case. (I'm not familiar with all extensions from gogo.)

nockty avatar Sep 12 '23 12:09 nockty

we could think of adding an unsafe feature providing unsafe methods to unmarshal messages, which doesn't need (2). This would affect all fields of the message, which should be OK, shouldn't it?

Not particularly for our use case. Our messages tend to have a lot of string data and most of them should be un-marshaled safely. It is only for a handful of fields that we opt to unmarshal them in an unsafe manner.

kevinconaway avatar Sep 26 '23 14:09 kevinconaway