Re: [protobuf] Re: Converting JSON Text Into PB Bytes Type

2011-01-03 Thread Siju Varghese
You could use https://github.com/sijuv/protobuf-codec . You can check the
test case at
https://github.com/sijuv/protobuf-codec/blob/master/protobuf-codec-json/src/test/java/protobuf/codec/json/JsonCodecTest.javafor
usage. This library is listed under the google protobuf
ThirdPartyAddOns
wiki as Another JSON encoder/decoder for
Javahttps://github.com/sijuv/protobuf-codec.


Let me know if you run into any issues.

Regards.

On Wed, Dec 29, 2010 at 4:34 AM, Kenton Varda ken...@google.com wrote:

 You should probably contact the authors of protobuf-java-format; I'm not
 sure if they pay attention to this list.

 Base64 is the best way to encode arbitrary (non-text) data as text.
  However, it's really up to the JSON converter code you are using to decide
 what format to use.  As far as I know, JSON does not specify any particular
 encoding for arbitrary bytes.


 On Sat, Dec 25, 2010 at 2:40 AM, yalmasri y.alma...@gmail.com wrote:

 Thanks for the reply.

 I encoded Hello world in Base64 and I got this SGVsbG8gd29ybGQ=.
 That doesn't look close to the format I sent in the question. Here's
 the code snippet I used:

 import org.apache.commons.codec.binary.Base64;
 public class Codec {
public static void main(String[] args) {
try {
String clearText = Hello world;
// Base64
System.out.println(Encoded:  +
 Base64.encodeBase64String(clearText.getBytes()));
} catch (Exception e) {
e.printStackTrace();
}
}
 }

 I'm using this: http://code.google.com/p/protobuf-java-format/ for
 JSON -- PB conversion


 On Dec 23, 3:48 am, Kenton Varda ken...@google.com wrote:
  You will probably need to base64-encode bytes fields before embedding
 them
  in JSON, since JSON is a text format.
 
  Which JSON - protobuf converter are you using?  Or did you write your
 own?
 
  On Tue, Dec 21, 2010 at 11:41 PM, yalmasri y.alma...@gmail.com wrote:
   Hello,
 
   One of our customers is still using legacy Java 1.4 and therefore
   could not use PB. For that we created an intermediate service that
   receives text messages in plain JSON format then convert them into
   generated PB objects.
 
   In one object we have a field named desc of type bytes which will
   hold a textual description of the arriving message. When the customer
   wants to send English text for desc the value in JSON will be plain
   readable English, but if non-ASCII is to be used, how the value in
   JSON will look like? It look to me something like:
 
   \0069\0062\006J\0062\006J\000 \006\'\006D\0069\006E\006J\006D\006\f
   \000 \006D\006B\006/\000 \006\'\006F\006*\006G\006I\000
 
   But I really don't know how to get this out of non-ASCII characters.
 
   Can anyone help?
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Protocol Buffers group.
   To post to this group, send email to proto...@googlegroups.com.
   To unsubscribe from this group, send email to
   protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@googlegroups.com
 protobuf%2bunsubscr...@googlegroups.comprotobuf%252bunsubscr...@googlegroups.com
 
   .
   For more options, visit this group at
  http://groups.google.com/group/protobuf?hl=en.

 --
 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To post to this group, send email to proto...@googlegroups.com.
 To unsubscribe from this group, send email to
 protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/protobuf?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To post to this group, send email to proto...@googlegroups.com.
 To unsubscribe from this group, send email to
 protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/protobuf?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



Re: [protobuf] Re: Converting JSON Text Into PB Bytes Type

2010-12-28 Thread Kenton Varda
You should probably contact the authors of protobuf-java-format; I'm not
sure if they pay attention to this list.

Base64 is the best way to encode arbitrary (non-text) data as text.
 However, it's really up to the JSON converter code you are using to decide
what format to use.  As far as I know, JSON does not specify any particular
encoding for arbitrary bytes.

On Sat, Dec 25, 2010 at 2:40 AM, yalmasri y.alma...@gmail.com wrote:

 Thanks for the reply.

 I encoded Hello world in Base64 and I got this SGVsbG8gd29ybGQ=.
 That doesn't look close to the format I sent in the question. Here's
 the code snippet I used:

 import org.apache.commons.codec.binary.Base64;
 public class Codec {
public static void main(String[] args) {
try {
String clearText = Hello world;
// Base64
System.out.println(Encoded:  +
 Base64.encodeBase64String(clearText.getBytes()));
} catch (Exception e) {
e.printStackTrace();
}
}
 }

 I'm using this: http://code.google.com/p/protobuf-java-format/ for
 JSON -- PB conversion


 On Dec 23, 3:48 am, Kenton Varda ken...@google.com wrote:
  You will probably need to base64-encode bytes fields before embedding
 them
  in JSON, since JSON is a text format.
 
  Which JSON - protobuf converter are you using?  Or did you write your
 own?
 
  On Tue, Dec 21, 2010 at 11:41 PM, yalmasri y.alma...@gmail.com wrote:
   Hello,
 
   One of our customers is still using legacy Java 1.4 and therefore
   could not use PB. For that we created an intermediate service that
   receives text messages in plain JSON format then convert them into
   generated PB objects.
 
   In one object we have a field named desc of type bytes which will
   hold a textual description of the arriving message. When the customer
   wants to send English text for desc the value in JSON will be plain
   readable English, but if non-ASCII is to be used, how the value in
   JSON will look like? It look to me something like:
 
   \0069\0062\006J\0062\006J\000 \006\'\006D\0069\006E\006J\006D\006\f
   \000 \006D\006B\006/\000 \006\'\006F\006*\006G\006I\000
 
   But I really don't know how to get this out of non-ASCII characters.
 
   Can anyone help?
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Protocol Buffers group.
   To post to this group, send email to proto...@googlegroups.com.
   To unsubscribe from this group, send email to
   protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@googlegroups.com
 protobuf%2bunsubscr...@googlegroups.comprotobuf%252bunsubscr...@googlegroups.com
 
   .
   For more options, visit this group at
  http://groups.google.com/group/protobuf?hl=en.

 --
 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To post to this group, send email to proto...@googlegroups.com.
 To unsubscribe from this group, send email to
 protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/protobuf?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.