static RoutableFactory createGetBucketStateReplyFactory() {
        return ProtobufCodecBuilder
                .of(GetBucketStateReply.class, DocapiInspect.GetBucketStateResponse.class)
                .encoder((apiReply) -> {
                    var builder = DocapiInspect.GetBucketStateResponse.newBuilder();
                    for (var state : apiReply.getBucketState()) {
                        var stateBuilder = DocapiInspect.DocumentState.newBuilder()
                                .setTimestamp(state.getTimestamp())
                                .setIsTombstone(state.isRemoveEntry());
                        if (state.hasDocId()) {
                            stateBuilder.setDocumentId(toProtoDocId(state.getDocId()));
                        } else {
                            stateBuilder.setGlobalId(toProtoGlobalId(state.getGid()));
                        }
                        builder.addStates(stateBuilder);
                    }
                    return builder.build();
                })
                .decoder(DocapiInspect.GetBucketStateResponse.parser(), (protoReply) -> {
                    var reply = new GetBucketStateReply();
                    for (var state : protoReply.getStatesList()) {
                        if (state.hasDocumentId()) {
                            reply.getBucketState().add(new DocumentState(
                                    fromProtoDocId(state.getDocumentId()),
                                    state.getTimestamp(),
                                    state.getIsTombstone()));
                        } else {
                            reply.getBucketState().add(new DocumentState(
                                    fromProtoGlobalId(state.getGlobalId()),
                                    state.getTimestamp(),
                                    state.getIsTombstone()));
                        }
                    }
                    return reply;
                })
                .build();
    }
Implementation of MessageBus message request/response serialization built around Protocol Buffers.
documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RoutableFactories80.java