How can I get the size of msg before grpc send it to client?

42 views
Skip to first unread message

Grpc learner

unread,
Aug 8, 2018, 4:14:35 PM8/8/18
to grpc.io
Like how many bytes it uses.

Christopher Warrington - MSFT

unread,
Aug 8, 2018, 5:20:13 PM8/8/18
to grpc.io
On Wednesday, August 8, 2018 at 1:14:35 PM UTC-7, Grpc learner wrote:

> How can I get the size of msg before grpc send it to client? Like how many
> bytes it uses.

Assume you had a magic function that returned this value: how would you use
it?

Do you only care about the size of the message itself, or are you interested
in the amount of data gRPC will send over the network as well? (E.g.,
metadata, compression, framing data as well)

Are you using Protocol Buffers for your messages or something else?

Which language(s) are you programming in?

--
Christopher Warrington
Microsoft Corp.

Grpc learner

unread,
Aug 8, 2018, 6:01:02 PM8/8/18
to grpc.io
Hi Christopher,
Thanks for your reply!

I am thinking how to use this function to check if the msg is larger than the threshold of the channel we are using. and trying to avoid some resources exhaust issue.
I am using java and gprc 1.13.1 and protobuf 3.5.1.

Christopher Warrington - MSFT

unread,
Aug 9, 2018, 7:46:16 PM8/9/18
to grpc.io

On Wednesday, August 8, 2018 at 3:01:02 PM UTC-7, Grpc learner wrote:
> I am thinking how to use this function to check if the msg is larger than
> the threshold of the channel we are using. and trying to avoid some
> resources exhaust issue. I am using java and gprc 1.13.1 and protobuf
> 3.5.1.

I belive then that you want com.google.protobuf.MessageList.getSerializedSize() [1].

[1]: https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/MessageLite#getSerializedSize--

Christopher Warrington - MSFT

unread,
Aug 9, 2018, 7:47:06 PM8/9/18
to grpc.io
> I belive then that you want com.google.protobuf.MessageList.getSerializedSize() [1].

Correction: the interface is MessageLite, not MessageList.

Grpc learner

unread,
Aug 9, 2018, 8:40:33 PM8/9/18
to grpc.io
Hi Christopher,

Got it!
Thanks for the reply!
Reply all
Reply to author
Forward
0 new messages