/** * Serialized protobuf of <code>state</code> with pb magic prefix prepended suitable for use as * content of a peer-state znode under a peer cluster id as in * /hbase/replication/peers/PEER_ID/peer-state. */ protected static byte[] toByteArray(final ReplicationProtos.ReplicationState.State state) { ReplicationProtos.ReplicationState msg = ReplicationProtos.ReplicationState.newBuilder().setState(state).build(); // There is no toByteArray on this pb Message? // 32 bytes is default which seems fair enough here. try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { CodedOutputStream cos = CodedOutputStream.newInstance(baos, 16); msg.writeTo(cos); cos.flush(); baos.flush(); return ProtobufUtil.prependPBMagic(baos.toByteArray()); } catch (IOException e) { throw new RuntimeException(e); } } }
private static void writeToCOS(Message result, Message header, int totalSize, ByteBuffer pbBuf) throws IOException { ByteBufferUtils.putInt(pbBuf, totalSize); // create COS that works on BB CodedOutputStream cos = CodedOutputStream.newInstance(pbBuf); if (header != null) { cos.writeMessageNoTag(header); } if (result != null) { cos.writeMessageNoTag(result); } cos.flush(); cos.checkNoSpaceLeft(); }
/** * Serialized protobuf of <code>state</code> with pb magic prefix prepended suitable for use as * content of a peer-state znode under a peer cluster id as in * /hbase/replication/peers/PEER_ID/peer-state. */ protected static byte[] toByteArray(final ReplicationProtos.ReplicationState.State state) { ReplicationProtos.ReplicationState msg = ReplicationProtos.ReplicationState.newBuilder().setState(state).build(); // There is no toByteArray on this pb Message? // 32 bytes is default which seems fair enough here. try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { CodedOutputStream cos = CodedOutputStream.newInstance(baos, 16); msg.writeTo(cos); cos.flush(); baos.flush(); return ProtobufUtil.prependPBMagic(baos.toByteArray()); } catch (IOException e) { throw new RuntimeException(e); } } }