I am very new to programming. Sorry if it's a too beginner question.
I am studying protocol buffers for homework. and I don't know how to get bytes from Message.
Here is the exapmple below from Google Protocol Buffers Documentation,
message Test1 {
required int32 a = 1;
}
In an application, you create a Test1 message and set a to 150. You then serialize the message to an output stream. If you were able to examine the encoded message, you'd see three bytes:
08 96 01
I am using Eclipse and Java. I created code below.
package com.example.tutorial;
import java.util.Scanner;
import com.example.tutorial.TestProtos.Test1;
import com.example.tutorial.TestProtos.Test1OrBuilder;
public class TestByte {
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int a = sc.nextInt();
Test1.Builder t = Test1.newBuilder();
Test1 obj = t.setA(a).build();
byte[] arr = obj.toByteArray();
System.out.println("byte: "+arr);
when I enter '150', it gives me
byte: [B@45ee12a7
I want to get three bytes like the example in google documentation. I am asking how to get the bytes from encoded message using protocol buffers.
can anyone tell me how? Thank you!!