public int estimatedSize(T value) { return value.serializedSizeFramed(); }
public void encode(T value, DataOutput dataOut) throws IOException { value.writeFramed((OutputStream) dataOut); }
public void encode(T value, DataOutput dataOut) throws IOException { value.writeUnframed((OutputStream) dataOut); }
static public Buffer toFramedBuffer(MessageBuffer message) { try { int size = message.serializedSizeFramed(); BufferOutputStream baos = new BufferOutputStream(size); CodedOutputStream output = new CodedOutputStream(baos); message.writeFramed(output); Buffer rc = baos.toBuffer(); assert rc.length==size : "Did not write as much data as expected."; return rc; } catch (IOException e) { throw new RuntimeException("Serializing to a byte array threw an IOException " + "(should never happen).", e); } }
static public Buffer toUnframedBuffer(MessageBuffer message) { try { int size = message.serializedSizeUnframed(); BufferOutputStream baos = new BufferOutputStream(size); CodedOutputStream output = new CodedOutputStream(baos); message.writeUnframed(output); Buffer rc = baos.toBuffer(); assert rc.length == size : "Did not write as much data as expected."; return rc; } catch (IOException e) { throw new RuntimeException("Serializing to a byte array threw an IOException " + "(should never happen).", e); } }
public int estimatedSize(T value) { return value.serializedSizeUnframed(); }
private void store(String ext, MessageBuffer<?,?> value) throws IOException { TarEntry entry = new TarEntry(seq + "." + ext); seq += 1; entry.setSize(value.serializedSizeFramed()); stream.putNextEntry(entry); value.writeFramed(stream); stream.closeEntry(); }
private void store(String ext, MessageBuffer<?,?> value) throws IOException { TarEntry entry = new TarEntry(seq + "." + ext); seq += 1; entry.setSize(value.serializedSizeFramed()); stream.putNextEntry(entry); value.writeFramed(stream); stream.closeEntry(); }
public static void writeMessage(CodedOutputStream output, int tag, MessageBuffer message) throws IOException { output.writeTag(tag, WireFormat.WIRETYPE_LENGTH_DELIMITED); message.writeFramed(output); }
public static int computeMessageSize(int tag, MessageBuffer message) { return CodedOutputStream.computeTagSize(tag) + message.serializedSizeFramed(); }
private void encodeProtobuf(Class<?> type, Object arg, DataByteArrayOutputStream target) throws IOException { if( !PBMessage.class.isAssignableFrom(type) ) { throw new IllegalArgumentException("Invalid "+name()+" serialization method: method argument not a "+PBMessage.class.getName()); } PBMessage msg = (PBMessage) arg; if( msg==null ) { return; } msg.freeze().writeUnframed(target); }
private void store(String ext, MessageBuffer<?,?> value) throws IOException { TarEntry entry = new TarEntry(seq + "." + ext); seq += 1; entry.setSize(value.serializedSizeFramed()); stream.putNextEntry(entry); value.writeFramed(stream); stream.closeEntry(); }
private void encodeProtobuf(Class<?> type, Object arg, DataByteArrayOutputStream target) throws IOException { if( !PBMessage.class.isAssignableFrom(type) ) { throw new IllegalArgumentException("Invalid "+name()+" serialization method: method argument not a "+PBMessage.class.getName()); } PBMessage msg = (PBMessage) arg; if( msg==null ) { return; } msg.freeze().writeUnframed(target); }