3

here is my code i'm still new with this protocol buffer how can i convert the protocol buffer to byte[] so that i can encrypte

for (ClientRequest req : check.getClientRequestGroup().getClientRequests()) {
            ClientRequestProtos.GetUnixDormantUsers.Builder guduBuilder =     ClientRequestProtos.GetUnixDormantUsers.newBuilder();
            guduBuilder.setCheckFiles(true);
            guduBuilder.setCheckProcesses(true);
            guduBuilder.setThreshold(30);
            guduBuilder.addExcludeUser("root");
            guduBuilder.addExcludeUser("bin");
            ClientRequestProtos.GetUnixDormantUsers guduMessage = guduBuilder.build();

            ClientRequestProtos.ClientRequest.Builder clientBuilder = ClientRequestProtos.ClientRequest.newBuilder();
            clientBuilder.setId(req.getId());
            clientBuilder.setSentAt(req.getSentAt().getTime());
            clientBuilder.setType(ClientRequestType.GET_UNIX_DORMANT_USERS);
            clientBuilder.setGetUnixDormantUsers(guduMessage);
            ClientRequestProtos.ClientRequest clientMessage = clientBuilder.build();



String ipAddress = mapHostIp.get(req.getHost());
                GenericUrl url = new GenericUrl("http://"+ ipAddress+":5736/request");
byte[] content; // convert protocol buffers to byte[]


            byte[] encrypted = Encrypt.encrypt(content);
            HttpRequest request = requestFactory.buildPostRequest(url, new ByteArrayContent(null, encrypted));
            request.execute();
        }

1 Answer 1

10

Just call the toByteArray method on the message:

byte[] content = clientMessage.toByteArray();
Sign up to request clarification or add additional context in comments.

6 Comments

is there any way to convert bytearray to Protobuf.
@unknown_11: You need to be much more precise about what you're trying to do - but rather than adding a comment on a post from nearly 9 years ago, I suggest you ask a new, detailed question.
thanks for replying @jon Skeet, actually I am working on an kafka consumer, and I am looking for the way to produce prtobuf data from kafka console producer to test my application
@unknown_11: Please don't provide any details here - instead, ask a new question.
Actually I don't have the access to ask questions that's why I asked in comment section.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.