You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2022/07/22 03:54:28 UTC

[GitHub] [servicecomb-java-chassis] lbc97 commented on issue #3198: RPC调用时body中有emoji等unicode时buffer转换会无法识别unicode

lbc97 commented on issue #3198:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3198#issuecomment-1192152228

   
   
   
   > 补充一个demo
   > 
   > ```java
   >     @Test
   >     public void test() throws Exception {
   > 
   >         TextMessage message = new TextMessage("📣");
   >         System.out.println(Arrays.toString("📣".getBytes(StandardCharsets.UTF_8)));
   >         System.out.println(Arrays.toString("\uD83D\uDCE3".getBytes(StandardCharsets.UTF_8)));
   >         // 转义后每个字符作为String
   >         System.out.println(Arrays.toString("\\uD83D\\uDCE3".getBytes(StandardCharsets.UTF_8)));
   >         Buffer requestBody;
   >         try (BufferOutputStream output = new BufferOutputStream()) {
   >             RestObjectMapperFactory.getConsumerWriterMapper().writeValue(output, message);
   >             requestBody = output.getBuffer();
   >         }
   >         System.out.println(Arrays.toString(requestBody.getBytes()));
   >     }
   > ```
   > 
   > 结果是 [-16, -97, -109, -93] [-16, -97, -109, -93] [92, 117, 68, 56, 51, 68, 92, 117, 68, 67, 69, 51] [123, 34, 116, 34, 58, 34, **92, 117, 68, 56, 51, 68, 92, 117, 68, 67, 69, 51**, 34, 125]
   > 
   > 可以看到buffer里的emoji变成了错误的内容,当成了非unicode来处理
   
   你那个TextMessage是啥啊


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org