Given a proto file:
syntax = "proto3";
package hello;
message TopGreeting {
NestedGreeting greeting = 1;
}
message NestedGreeting {
Greeting greeting = 1;
}
message Greeting {
string message = 1;
}
and the code:
public class Main {
public static void main(String[] args) {
System.out.printf("From top: %s%n", newGreeting("오늘은 무슨 요일입니까?"));
System.out.printf("Directly: %s%n", "오늘은 무슨 요일입니까?");
System.out.printf("ByteString: %s", newGreeting("오늘은 무슨 요일입니까?").toByteString().toStringUtf8());
}
private static Hello.TopGreeting newGreeting(String message) {
Hello.Greeting greeting = Hello.Greeting.newBuilder()
.setMessage(message)
.build();
Hello.NestedGreeting nestedGreeting = Hello.NestedGreeting.newBuilder()
.setGreeting(greeting)
.build();
return Hello.TopGreeting.newBuilder()
.setGreeting(nestedGreeting)
.build();
}
}
Output
From top: greeting {
greeting {
message: "\354\230\244\353\212\230\354\235\200 \353\254\264\354\212\250 \354\232\224\354\235\274\354\236\205\353\213\210\352\271\214?"
}
}
Directly: 오늘은 무슨 요일입니까?
ByteString:
%
#
!오늘은 무슨 요일입니까?
How do I print the message in a human-readable way? As you can see, converting to ByteString
prints the UTF-8 characters alright, but also prints some other garbage %
and #
.
newgreeting
? – Springfield