Skip to content

Instantly share code, notes, and snippets.

@subfuzion
Last active February 26, 2024 20:39
Show Gist options
  • Save subfuzion/ecfc45c4e8dfb28e31fb5a8bf2f8282c to your computer and use it in GitHub Desktop.
Save subfuzion/ecfc45c4e8dfb28e31fb5a8bf2f8282c to your computer and use it in GitHub Desktop.
Protocol Buffer example of importing and using empty

How to import and indicate empty request or reply messages:

import "google/protobuf/empty.proto";

service SomeService {
    rpc SomeOperation (google.protobuf.Empty) returns (google.protobuf.Empty) {}
}
@inge4pres
Copy link

If an rpc returns Empty, is there still a message sent over the wire?

I think yes: the response contains at least the status code from the RPC executon on the server. The HTTP payload should have an empty body though.

@akshayjshah
Copy link

akshayjshah commented Jul 22, 2022

Assuming we're talking about gRPC, there's still data sent over the wire.

The response body has a five-byte prefix, which should be all zeros: the first byte indicates whether the message is compressed, and the next four bytes are a 32-bit unsigned integer. Empty protobuf messages serialize to zero bytes, and google.protobuf.Empty is always empty, so there's no data following the initial 5 bytes.

You'll also end up sending at least one trailer with the status code (grpc-status: 0). Depending on your implementation, you may also send the grpc-message and grpc-status-details-bin trailers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment