public static int getSkippableIndexOverheadSize(Type type, int recordSize) { switch (type) { case INT: case LONG: case DOUBLE: case FLOAT: case BYTES: case STRING: case BOOLEAN: case ENUM: case ANY: return 0; case RECORD: case MAP: case LIST: return CodedOutputStream.computeUInt32SizeNoTag(recordSize); } throw new IllegalArgumentException("?"); }
private static int sizeOfMap(MapSchema mapSchema, Map value) { Set<Map.Entry> entrySet = value.entrySet(); Iterator<Map.Entry> it = entrySet.iterator(); int size = CodedOutputStream.computeInt32SizeNoTag(value.size()); while (it.hasNext()) { Map.Entry entry = it.next(); if (entry.getKey() == null || entry.getValue() == null) { continue; } int keySize = sizeOf(mapSchema.getKeySchema(), entry.getKey()); if (mapSchema.getKeySchema().getType().isAlwaysSkippable()) { keySize += getSkippableIndexOverheadSize(mapSchema.getKeySchema().getType(), keySize); } int valSize = sizeOf(mapSchema.getValueSchema(), entry.getValue()); if (mapSchema.getValueSchema().getType().isAlwaysSkippable()) { valSize += getSkippableIndexOverheadSize(mapSchema.getValueSchema().getType(), valSize); } size += keySize + valSize; } return size; }
/** * Size of full record including mandatory header length * * @param rec * @return */ public static int sizeOfRecord(Record rec) { // header bytes int size = CodedOutputStream.computeByteArraySizeNoTag(createHeader(rec)); // write fields for (Field field : rec.getSchema().getFields()) { // ignore removed fields if (field.isRemoved() || !rec.hasValue(field.getOrd())) { continue; } Object val = rec.get(field.getOrd()); // add each field size int fieldValueSize = sizeOf(field.getSchema(), val); // extra info size for skipping if (field.skippable()) { fieldValueSize += getSkippableIndexOverheadSize(field.getSchema().getType(), fieldValueSize); } size += fieldValueSize; } // plus length header return size; }
private static FullHttpResponse getDino(XrpcRequest request, List<Dino> dinos) { try { DinoGetRequest getRequest = DinoGetRequest.parseFrom(CodedInputStream.newInstance(request.getData().nioBuffer())); Optional<Dino> dinoOptional = dinos.stream().filter(xs -> xs.getName().equals(getRequest.getName())).findFirst(); if (dinoOptional.isPresent()) { DinoGetReply getReply = DinoGetReply.newBuilder().setDino(dinoOptional.get()).build(); ByteBuf resp = request.getByteBuf(); resp.ensureWritable(CodedOutputStream.computeMessageSizeNoTag(getReply), true); getReply.writeTo(new ByteBufOutputStream(resp)); return Recipes.newResponse( HttpResponseStatus.OK, request.getByteBuf().writeBytes(resp), Recipes.ContentType.Application_Octet_Stream); } } catch (IOException e) { return Recipes.newResponseBadRequest("Malformed GetDino Request: " + e.getMessage()); } return Recipes.newResponseOk("Dino not Found"); }
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof ChannelBuffer)) { return msg; } ChannelBuffer body = (ChannelBuffer) msg; int length = body.readableBytes(); ChannelBuffer header = channel.getConfig().getBufferFactory() .getBuffer(body.order(), CodedOutputStream.computeRawVarint64Size(length) + 4); CodedOutputStream codedOutputStream = CodedOutputStream.newInstance(new ChannelBufferOutputStream(header)); codedOutputStream.writeRawVarint64(length); int value = 0x0; value |= (0x0 & 0xff);// network version value |= ((0x0 & 0xff) << 8);// type if (ctx.getPipeline().get("cryptoEncoder") != null) value |= ((0x1 & 0xf) << 16);// crypto type else value |= ((0x0 & 0xf) << 16);// crypto type value |= ((0x0 & 0xfff) << 20);// version codedOutputStream.writeRawLittleEndian32(value); codedOutputStream.flush(); return wrappedBuffer(header, body); }
public void writeTo(CodedOutputStream output) throws IOException { this.getSerializedSize(); if((this.bitField0_ & 1) == 1) { output.writeBytes(1, this.getBodyBytes()); } for(int i = 0; i < this.attachments_.size(); ++i) { output.writeMessage(2, (MessageLite)this.attachments_.get(i)); } if((this.bitField0_ & 2) == 2) { output.writeMessage(3, this.group_); } if((this.bitField0_ & 4) == 4) { output.writeUInt32(4, this.flags_); } if((this.bitField0_ & 8) == 8) { output.writeMessage(5, this.sync_); } this.getUnknownFields().writeTo(output); }
public int getSerializedSize() { int size = this.memoizedSerializedSize; if(size != -1) { return size; } else { size = 0; if((this.bitField0_ & 1) == 1) { size += CodedOutputStream.computeBytesSize(1, this.getDestinationBytes()); } if((this.bitField0_ & 2) == 2) { size += CodedOutputStream.computeUInt64Size(2, this.timestamp_); } size += this.getUnknownFields().getSerializedSize(); this.memoizedSerializedSize = size; return size; } }
public void writeTo(CodedOutputStream output) throws IOException { this.getSerializedSize(); if((this.bitField0_ & 1) == 1) { output.writeBytes(1, this.id_); } if((this.bitField0_ & 2) == 2) { output.writeEnum(2, this.type_.getNumber()); } if((this.bitField0_ & 4) == 4) { output.writeBytes(3, this.getNameBytes()); } for(int i = 0; i < this.members_.size(); ++i) { output.writeBytes(4, this.members_.getByteString(i)); } if((this.bitField0_ & 8) == 8) { output.writeMessage(5, this.avatar_); } this.getUnknownFields().writeTo(output); }
public void writeTo(CodedOutputStream output) throws IOException { this.getSerializedSize(); if((this.bitField0_ & 1) == 1) { output.writeFixed64(1, this.id_); } if((this.bitField0_ & 2) == 2) { output.writeBytes(2, this.getContentTypeBytes()); } if((this.bitField0_ & 4) == 4) { output.writeBytes(3, this.key_); } this.getUnknownFields().writeTo(output); }
public int getSerializedSize() { int size = this.memoizedSerializedSize; if(size != -1) { return size; } else { size = 0; if((this.bitField0_ & 1) == 1) { size += CodedOutputStream.computeFixed64Size(1, this.id_); } if((this.bitField0_ & 2) == 2) { size += CodedOutputStream.computeBytesSize(2, this.getContentTypeBytes()); } if((this.bitField0_ & 4) == 4) { size += CodedOutputStream.computeBytesSize(3, this.key_); } size += this.getUnknownFields().getSerializedSize(); this.memoizedSerializedSize = size; return size; } }
/** * Serializes the given protobuf object into a Netty {@link ChannelBuffer}. * @param method The name of the method of the RPC we're going to send. * @param pb The protobuf to serialize. * @return A new channel buffer containing the serialized protobuf, with * enough free space at the beginning to tack on the RPC header. */ static final ChannelBuffer toChannelBuffer(final byte[] method, final AbstractMessageLite pb) { final int pblen = pb.getSerializedSize(); final int vlen = CodedOutputStream.computeRawVarint32Size(pblen); final byte[] buf = new byte[4 + 19 + method.length + vlen + pblen]; try { final CodedOutputStream out = CodedOutputStream.newInstance(buf, 4 + 19 + method.length, vlen + pblen); out.writeRawVarint32(pblen); pb.writeTo(out); out.checkNoSpaceLeft(); } catch (IOException e) { throw new RuntimeException("Should never happen", e); } return ChannelBuffers.wrappedBuffer(buf); }
/** * Saves track properties by modifying only file tail. */ public void saveProperties(FileDataSource source) throws Exception { Track track = source.tracks.get(0); // Prepare new properties tail ByteBuffer buffer = ByteBuffer.allocate(getSerializedPropertiesSize(track)); CodedOutputStream output = CodedOutputStream.newInstance(buffer); output.writeBytes(FIELD_NAME, ByteString.copyFromUtf8(track.name)); output.writeUInt32(FIELD_COLOR, track.style.color); output.writeFloat(FIELD_WIDTH, track.style.width); output.flush(); // Modify tail of file File file = new File(source.path); long createTime = file.lastModified(); RandomAccessFile access = new RandomAccessFile(file, "rw"); access.setLength(source.propertiesOffset + 1); access.seek(source.propertiesOffset); access.write(buffer.array()); access.close(); //noinspection ResultOfMethodCallIgnored file.setLastModified(createTime); }
private static <T> List<byte[]> toProtos(ProtobufCodec<T> codec, Collection<T> objs) throws OrmException { List<byte[]> result = Lists.newArrayListWithCapacity(objs.size()); ByteArrayOutputStream out = new ByteArrayOutputStream(256); try { for (T obj : objs) { out.reset(); CodedOutputStream cos = CodedOutputStream.newInstance(out); codec.encode(obj, cos); cos.flush(); result.add(out.toByteArray()); } } catch (IOException e) { throw new OrmException(e); } return result; }
private byte[] setupResponseForProtobuf( RpcResponseHeaderProto header, Writable rv) throws IOException { Message payload = (rv != null) ? ((RpcWritable.ProtobufWrapper)rv).getMessage() : null; int length = getDelimitedLength(header); if (payload != null) { length += getDelimitedLength(payload); } byte[] buf = new byte[length + 4]; CodedOutputStream cos = CodedOutputStream.newInstance(buf); // the stream only supports little endian ints cos.writeRawByte((byte)((length >>> 24) & 0xFF)); cos.writeRawByte((byte)((length >>> 16) & 0xFF)); cos.writeRawByte((byte)((length >>> 8) & 0xFF)); cos.writeRawByte((byte)((length >>> 0) & 0xFF)); cos.writeRawVarint32(header.getSerializedSize()); header.writeTo(cos); if (payload != null) { cos.writeRawVarint32(payload.getSerializedSize()); payload.writeTo(cos); } return buf; }
@Override protected eu.hellek.gba.proto.SearchResultProtos.SearchResultProxy doInBackground(Void... params) { try { URL url = new URL("http://"+appurl+"/rm/DirectSearchServlet"); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/x-protobuf"); conn.setRequestProperty("Content-Length", ""+req.getSerializedSize()); OutputStream out = conn.getOutputStream(); CodedOutputStream cout = CodedOutputStream.newInstance(out); req.writeTo(cout); cout.flush(); out.close(); eu.hellek.gba.proto.SearchResultProtos.SearchResultProxy srp = eu.hellek.gba.proto.SearchResultProtos.SearchResultProxy.parseFrom(conn.getInputStream()); return srp; } catch(Exception e) { Log.e("DirectSearchTask", "Error in search", e); e.printStackTrace(); return null; } }
/** * Initializes the appropriate deserialize method based on presence of dependency. * * <p>{@link InjectingObjectCodec#serialize} if dependency is non-null and {@link * ObjectCodec#serialize} otherwise. * * @param encodedType type being serialized * @param dependency type being injected */ static MethodSpec.Builder initializeSerializeMethodBuilder( TypeElement encodedType, @Nullable TypeElement dependency) { MethodSpec.Builder builder = MethodSpec.methodBuilder("serialize") .addModifiers(Modifier.PUBLIC) .returns(void.class) .addAnnotation(Override.class) .addException(SerializationException.class) .addException(IOException.class); if (dependency != null) { builder.addParameter(TypeName.get(dependency.asType()), "dependency"); } return builder .addParameter(TypeName.get(encodedType.asType()), "input") .addParameter(CodedOutputStream.class, "codedOut"); }
/** * Compute object size no tag. * * @param o the o * @return the int */ public static int computeObjectSizeNoTag(Object o) { int size = 0; if (o == null) { return size; } Class cls = o.getClass(); Codec target = ProtobufProxy.create(cls); try { size = target.size(o); size = size + CodedOutputStream.computeRawVarint32Size(size); return size; } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } }
@Override public int serializeTo(int sourceId, Namespaces namespaces, OutputStream output) throws IOException { SerializeFormat.DataValue.Builder builder = XmlResourceValues.newSerializableDataValueBuilder(sourceId); SerializeFormat.DataValue value = builder .setXmlValue( builder .getXmlValueBuilder() .setType(XmlType.PLURAL) .putAllNamespace(namespaces.asMap()) .putAllAttribute(attributes) .putAllMappedStringValue(values)) .build(); value.writeDelimitedTo(output); return CodedOutputStream.computeUInt32SizeNoTag(value.getSerializedSize()) + value.getSerializedSize(); }
public int getSerializedSize() { int size = memoizedSerializedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += CodedOutputStream .computeUInt32Size(1, version_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += CodedOutputStream .computeBytesSize(2, getReleaseBytes()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { size += CodedOutputStream .computeBytesSize(3, getOsBytes()); } if (((bitField0_ & 0x00000008) == 0x00000008)) { size += CodedOutputStream .computeBytesSize(4, getOsVersionBytes()); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; }
public int getSerializedSize() { int size = memoizedSerializedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += CodedOutputStream .computeEnumSize(1, type_.getNumber()); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += CodedOutputStream .computeBytesSize(2, getReasonBytes()); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; }
public void writeTo(CodedOutputStream output) throws IOException { getSerializedSize(); if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeUInt32(1, session_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeUInt32(2, maxBandwidth_); } if (((bitField0_ & 0x00000004) == 0x00000004)) { output.writeBytes(3, getWelcomeTextBytes()); } if (((bitField0_ & 0x00000008) == 0x00000008)) { output.writeUInt64(4, permissions_); } getUnknownFields().writeTo(output); }
@Override public int serializeTo(int sourceId, Namespaces namespaces, OutputStream output) throws IOException { Builder xmlValue = SerializeFormat.DataValueXml.newBuilder() .setType(XmlType.ID) .putAllNamespace(namespaces.asMap()); if (value != null) { xmlValue.setValue(value); } SerializeFormat.DataValue dataValue = XmlResourceValues.newSerializableDataValueBuilder(sourceId).setXmlValue(xmlValue).build(); dataValue.writeDelimitedTo(output); return CodedOutputStream.computeUInt32SizeNoTag(dataValue.getSerializedSize()) + dataValue.getSerializedSize(); }
public int getSerializedSize() { int size = memoizedSerializedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += CodedOutputStream .computeUInt32Size(1, session_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += CodedOutputStream .computeUInt32Size(2, actor_); } if (((bitField0_ & 0x00000004) == 0x00000004)) { size += CodedOutputStream .computeBytesSize(3, getReasonBytes()); } if (((bitField0_ & 0x00000008) == 0x00000008)) { size += CodedOutputStream .computeBoolSize(4, ban_); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; }
public void writeTo(CodedOutputStream output) throws IOException { getSerializedSize(); if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeUInt32(1, actor_); } for (int i = 0; i < session_.size(); i++) { output.writeUInt32(2, session_.get(i)); } for (int i = 0; i < channelId_.size(); i++) { output.writeUInt32(3, channelId_.get(i)); } for (int i = 0; i < treeId_.size(); i++) { output.writeUInt32(4, treeId_.get(i)); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeBytes(5, getMessageBytes()); } getUnknownFields().writeTo(output); }
public void writeTo(CodedOutputStream output) throws IOException { getSerializedSize(); if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeUInt32(1, permission_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeUInt32(2, channelId_); } if (((bitField0_ & 0x00000004) == 0x00000004)) { output.writeUInt32(3, session_); } if (((bitField0_ & 0x00000008) == 0x00000008)) { output.writeBytes(4, getReasonBytes()); } if (((bitField0_ & 0x00000010) == 0x00000010)) { output.writeEnum(5, type_.getNumber()); } if (((bitField0_ & 0x00000020) == 0x00000020)) { output.writeBytes(6, getNameBytes()); } getUnknownFields().writeTo(output); }
public void writeTo(CodedOutputStream output) throws IOException { getSerializedSize(); if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeBytes(1, getNameBytes()); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeBool(2, inherited_); } if (((bitField0_ & 0x00000004) == 0x00000004)) { output.writeBool(3, inherit_); } if (((bitField0_ & 0x00000008) == 0x00000008)) { output.writeBool(4, inheritable_); } for (int i = 0; i < add_.size(); i++) { output.writeUInt32(5, add_.get(i)); } for (int i = 0; i < remove_.size(); i++) { output.writeUInt32(6, remove_.get(i)); } for (int i = 0; i < inheritedMembers_.size(); i++) { output.writeUInt32(7, inheritedMembers_.get(i)); } getUnknownFields().writeTo(output); }
public void writeTo(CodedOutputStream output) throws IOException { getSerializedSize(); if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeBool(1, applyHere_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeBool(2, applySubs_); } if (((bitField0_ & 0x00000004) == 0x00000004)) { output.writeBool(3, inherited_); } if (((bitField0_ & 0x00000008) == 0x00000008)) { output.writeUInt32(4, userId_); } if (((bitField0_ & 0x00000010) == 0x00000010)) { output.writeBytes(5, getGroupBytes()); } if (((bitField0_ & 0x00000020) == 0x00000020)) { output.writeUInt32(6, grant_); } if (((bitField0_ & 0x00000040) == 0x00000040)) { output.writeUInt32(7, deny_); } getUnknownFields().writeTo(output); }
@Test public void testSerializeDeserializeInBulk() throws Exception { Integer value1 = 12345; Integer value2 = 67890; Integer value3 = 42; ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); CodedOutputStream codedOut = CodedOutputStream.newInstance(bytesOut); underTest.serialize(KNOWN_CLASSIFIER, value1, codedOut); underTest.serialize(KNOWN_CLASSIFIER, value2, codedOut); underTest.serialize(KNOWN_CLASSIFIER, value3, codedOut); codedOut.flush(); CodedInputStream codedIn = CodedInputStream.newInstance(bytesOut.toByteArray()); assertThat(underTest.deserialize(KNOWN_CLASSIFIER_BYTES, codedIn)).isEqualTo(value1); assertThat(underTest.deserialize(KNOWN_CLASSIFIER_BYTES, codedIn)).isEqualTo(value2); assertThat(underTest.deserialize(KNOWN_CLASSIFIER_BYTES, codedIn)).isEqualTo(value3); }
public void writeTo(CodedOutputStream output) throws IOException { getSerializedSize(); if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeBytes(1, getActionBytes()); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeBytes(2, getTextBytes()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { output.writeUInt32(3, context_); } if (((bitField0_ & 0x00000008) == 0x00000008)) { output.writeEnum(4, operation_.getNumber()); } getUnknownFields().writeTo(output); }
public int getSerializedSize() { int size = memoizedSerializedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += CodedOutputStream .computeBytesSize(1, getActionBytes()); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += CodedOutputStream .computeBytesSize(2, getTextBytes()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { size += CodedOutputStream .computeUInt32Size(3, context_); } if (((bitField0_ & 0x00000008) == 0x00000008)) { size += CodedOutputStream .computeEnumSize(4, operation_.getNumber()); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; }
public int getSerializedSize() { int size = memoizedSerializedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += CodedOutputStream .computeUInt32Size(1, session_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += CodedOutputStream .computeUInt32Size(2, channelId_); } if (((bitField0_ & 0x00000004) == 0x00000004)) { size += CodedOutputStream .computeBytesSize(3, getActionBytes()); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; }
public int getSerializedSize() { int size = memoizedSerializedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += CodedOutputStream .computeUInt32Size(1, userId_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += CodedOutputStream .computeBytesSize(2, getNameBytes()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { size += CodedOutputStream .computeBytesSize(3, getLastSeenBytes()); } if (((bitField0_ & 0x00000008) == 0x00000008)) { size += CodedOutputStream .computeUInt32Size(4, lastChannel_); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; }
public int getSerializedSize() { int size = memoizedSerializedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += CodedOutputStream .computeUInt32Size(1, id_); } for (int i = 0; i < targets_.size(); i++) { size += CodedOutputStream .computeMessageSize(2, targets_.get(i)); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; }
public void writeTo(CodedOutputStream output) throws IOException { getSerializedSize(); if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeInt32(1, alpha_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeInt32(2, beta_); } if (((bitField0_ & 0x00000004) == 0x00000004)) { output.writeBool(3, preferAlpha_); } if (((bitField0_ & 0x00000008) == 0x00000008)) { output.writeBool(4, opus_); } getUnknownFields().writeTo(output); }
public int getSerializedSize() { int size = memoizedSerializedSize; if (size != -1) return size; size = 0; if (((bitField0_ & 0x00000001) == 0x00000001)) { size += CodedOutputStream .computeInt32Size(1, alpha_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { size += CodedOutputStream .computeInt32Size(2, beta_); } if (((bitField0_ & 0x00000004) == 0x00000004)) { size += CodedOutputStream .computeBoolSize(3, preferAlpha_); } if (((bitField0_ & 0x00000008) == 0x00000008)) { size += CodedOutputStream .computeBoolSize(4, opus_); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; }
public void writeTo(CodedOutputStream output) throws IOException { getSerializedSize(); if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeUInt32(1, good_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeUInt32(2, late_); } if (((bitField0_ & 0x00000004) == 0x00000004)) { output.writeUInt32(3, lost_); } if (((bitField0_ & 0x00000008) == 0x00000008)) { output.writeUInt32(4, resync_); } getUnknownFields().writeTo(output); }
private void serializeOneNestedSet( Object children, CodedOutputStream codedOut, Map<Object, byte[]> childToDigest) throws IOException, SerializationException { // Serialize nested set into an inner byte array so we can take its digest ByteArrayOutputStream childOutputStream = new ByteArrayOutputStream(); HashingOutputStream hashingOutputStream = new HashingOutputStream(Hashing.md5(), childOutputStream); CodedOutputStream childCodedOut = CodedOutputStream.newInstance(hashingOutputStream); if (children instanceof Object[]) { serializeMultiItemChildArray((Object[]) children, childToDigest, childCodedOut); } else if (children != NestedSet.EMPTY_CHILDREN) { serializeSingleItemChildArray(children, childCodedOut); } else { // Empty set childCodedOut.writeInt32NoTag(0); } childCodedOut.flush(); byte[] digest = hashingOutputStream.hash().asBytes(); codedOut.writeByteArrayNoTag(digest); byte[] childBytes = childOutputStream.toByteArray(); codedOut.writeByteArrayNoTag(childBytes); childToDigest.put(children, digest); }
public void writeTo(CodedOutputStream output) throws IOException { getSerializedSize(); if (((bitField0_ & 0x00000001) == 0x00000001)) { output.writeUInt32(1, maxBandwidth_); } if (((bitField0_ & 0x00000002) == 0x00000002)) { output.writeBytes(2, getWelcomeTextBytes()); } if (((bitField0_ & 0x00000004) == 0x00000004)) { output.writeBool(3, allowHtml_); } if (((bitField0_ & 0x00000008) == 0x00000008)) { output.writeUInt32(4, messageLength_); } if (((bitField0_ & 0x00000010) == 0x00000010)) { output.writeUInt32(5, imageMessageLength_); } getUnknownFields().writeTo(output); }
@Override protected void encode( ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception { int bodyLen = msg.readableBytes(); int headerLen = CodedOutputStream.computeRawVarint32Size(bodyLen); out.ensureWritable(headerLen + bodyLen); CodedOutputStream headerOut = CodedOutputStream.newInstance(new ByteBufOutputStream(out), headerLen); headerOut.writeRawVarint32(bodyLen); headerOut.flush(); out.writeBytes(msg, msg.readerIndex(), bodyLen); }