@Override public void writeTo(OUT message, ByteBuffer buffer) { buffer.put(message.toByteArray()); }
public static Value toValue(GeneratedMessage msg) { return new Value(msg.toByteArray()); }
@Override public byte[] inputEncode(Object input) throws IOException { if (input instanceof GeneratedMessage) { return ((GeneratedMessage) input).toByteArray(); } return null; }
public static byte[] toByteArray(Builder<?> builder) { return getGeneratedMessage(builder).toByteArray(); }
public static Value toValue(GeneratedMessage msg) { return new Value(msg.toByteArray()); }
@Override protected byte[] encodeRequestParams(TarsServantRequest request, String charsetName) throws ProtocolException { Object[] parameter = request.getMethodParameters(); if (TarsHelper.isCallback(request.getMethodInfo().getParametersList().get(0).getAnnotations())) { return ((GeneratedMessage) parameter[1]).toByteArray(); } return ((GeneratedMessage) parameter[0]).toByteArray(); }
/** * Encode custom protobuf variable length array. * * @param <T> the item type * @param items the list of items, not null * @return the encoded list, not null * @throws IOException, not null * @throws NullPointerException if any arguments are null */ public static <T extends GeneratedMessage> byte[] encode(List<T> items) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CodedOutputStream stream = CodedOutputStream.newInstance(bytes); for (T item : items) { byte[] encoded = item.toByteArray(); stream.writeRawVarint32(encoded.length); stream.writeRawBytes(encoded); } stream.flush(); return bytes.toByteArray(); } }
@Override protected byte[] encodeResult(TarsServantResponse response, String charsetName) { TarsServantRequest request = response.getRequest(); byte[] result = new byte[] {}; if (TarsHelper.isPing(request.getFunctionName())) { return result; } result = ((GeneratedMessage) response.getResult()).toByteArray(); return result; }
retMsg.setServiceId(key); if (ret != null && ret instanceof GeneratedMessage) { byte[] response = ((GeneratedMessage) ret).toByteArray(); retMsg.setData(response);
retMsg.setServiceId(key); if (ret != null && ret instanceof GeneratedMessage) { byte[] response = ((GeneratedMessage) ret).toByteArray(); retMsg.setData(response);
byte[] response = ((GeneratedMessage) ret).toByteArray(); retData.setData(response); byte[] response = ((GeneratedMessage) ret).toByteArray(); retData.setData(response);