當前位置: 首頁>>代碼示例>>Java>>正文


Java CodedOutputStream類代碼示例

本文整理匯總了Java中com.google.protobuf.CodedOutputStream的典型用法代碼示例。如果您正苦於以下問題:Java CodedOutputStream類的具體用法?Java CodedOutputStream怎麽用?Java CodedOutputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CodedOutputStream類屬於com.google.protobuf包,在下文中一共展示了CodedOutputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeTo

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
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);
}
 
開發者ID:Agilitum,項目名稱:TextSecureSMP,代碼行數:25,代碼來源:PushSMPMessageProtos.java

示例2: getSkippableIndexOverheadSize

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
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("?");
}
 
開發者ID:atlascon,項目名稱:travny,代碼行數:20,代碼來源:BinaryWriter.java

示例3: sizeOfMap

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
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;
}
 
開發者ID:atlascon,項目名稱:travny,代碼行數:22,代碼來源:BinaryWriter.java

示例4: sizeOfRecord

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:atlascon,項目名稱:travny,代碼行數:28,代碼來源:BinaryWriter.java

示例5: getDino

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
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");
}
 
開發者ID:Nordstrom,項目名稱:xrpc,代碼行數:26,代碼來源:Example.java

示例6: encode

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
@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);
}
 
開發者ID:mornsun,項目名稱:bdclient,代碼行數:25,代碼來源:ProtobufVarint64LengthFieldPrepender.java

示例7: getSerializedSize

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
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;
	}
}
 
開發者ID:Agilitum,項目名稱:TextSecureSMP,代碼行數:20,代碼來源:PushSMPMessageProtos.java

示例8: toChannelBuffer

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:OpenTSDB,項目名稱:asynccassandra,代碼行數:24,代碼來源:HBaseRpc.java

示例9: saveProperties

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:andreynovikov,項目名稱:trekarta,代碼行數:24,代碼來源:TrackManager.java

示例10: toProtos

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
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;
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:18,代碼來源:ChangeField.java

示例11: setupResponseForProtobuf

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
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;
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:24,代碼來源:Server.java

示例12: doInBackground

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
@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;
	}
}
 
開發者ID:Hellek1,項目名稱:viaja-facil,代碼行數:23,代碼來源:ViajaFacilActivity.java

示例13: initializeSerializeMethodBuilder

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
/**
 * 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");
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:26,代碼來源:AutoCodecUtil.java

示例14: computeObjectSizeNoTag

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:jhunters,項目名稱:jprotobuf,代碼行數:23,代碼來源:CodedConstant.java

示例15: serializeTo

import com.google.protobuf.CodedOutputStream; //導入依賴的package包/類
@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();
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:20,代碼來源:PluralXmlResourceValue.java


注:本文中的com.google.protobuf.CodedOutputStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。