Skip to content

Instantly share code, notes, and snippets.

@xfxyjwf
Created February 1, 2018 19:54
Show Gist options
  • Save xfxyjwf/98ae915d3a076c46586f4af7435e1f46 to your computer and use it in GitHub Desktop.
Save xfxyjwf/98ae915d3a076c46586f4af7435e1f46 to your computer and use it in GitHub Desktop.
protobuf Java example with 4-bytes UTF-8 characters.
import xiaofeng.A.Foo;
public class A {
public static void main(String[] argv) throws Exception {
Foo foo = Foo.newBuilder()
.setValue("\uD852\uDF62\uD83D\uDE00")
.build();
byte[] data = foo.toByteArray();
for (byte b : data) {
System.out.println(String.format("\\x%02X", b));
}
}
}
syntax = "proto2";
package xiaofeng;
message Foo {
optional string value = 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment