本文整理匯總了Java中com.google.protobuf.CodedOutputStream.writeUInt32方法的典型用法代碼示例。如果您正苦於以下問題:Java CodedOutputStream.writeUInt32方法的具體用法?Java CodedOutputStream.writeUInt32怎麽用?Java CodedOutputStream.writeUInt32使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.protobuf.CodedOutputStream
的用法示例。
在下文中一共展示了CodedOutputStream.writeUInt32方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
示例2: 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);
}
示例3: writeTo
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
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);
}
示例4: saveData
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
@Override
public void saveData(OutputStream outputStream, FileDataSource source, @Nullable ProgressListener progressListener) throws Exception {
if (source.tracks.size() != 1)
throw new Exception("Only single track can be saved in mtrack format");
Track track = source.tracks.get(0);
if (progressListener != null)
progressListener.onProgressStarted(track.points.size());
CodedOutputStream output = CodedOutputStream.newInstance(outputStream);
output.writeUInt32(FIELD_VERSION, VERSION);
int progress = 0;
for (Track.TrackPoint point : track.points) {
output.writeTag(FIELD_POINT, WireFormat.WIRETYPE_LENGTH_DELIMITED);
output.writeRawVarint32(getSerializedPointSize(point));
output.writeInt32(FIELD_POINT_LATITUDE, point.latitudeE6);
output.writeInt32(FIELD_POINT_LONGITUDE, point.longitudeE6);
output.writeFloat(FIELD_POINT_ALTITUDE, point.elevation);
output.writeFloat(FIELD_POINT_SPEED, point.speed);
output.writeFloat(FIELD_POINT_BEARING, point.bearing);
output.writeFloat(FIELD_POINT_ACCURACY, point.accuracy);
output.writeUInt64(FIELD_POINT_TIMESTAMP, point.time);
if (!point.continuous)
//noinspection ConstantConditions
output.writeBool(8, point.continuous);
progress++;
if (progressListener != null)
progressListener.onProgressChanged(progress);
}
output.writeBytes(FIELD_NAME, ByteString.copyFromUtf8(track.name));
output.writeUInt32(FIELD_COLOR, track.style.color);
output.writeFloat(FIELD_WIDTH, track.style.width);
output.flush();
outputStream.close();
if (progressListener != null)
progressListener.onProgressFinished();
}
示例5: writeObject
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
/**
* Write object to byte array by {@link FieldType}
*
* @param out
* @param order
* @param type
* @param o
* @throws IOException
*/
public static void writeObject(CodedOutputStream out, int order, FieldType type, Object o, boolean list)
throws IOException {
if (o == null) {
return;
}
if (type == FieldType.OBJECT) {
Class cls = o.getClass();
Codec target = ProtobufProxy.create(cls);
out.writeRawVarint32(makeTag(order, WireFormat.WIRETYPE_LENGTH_DELIMITED));
out.writeRawVarint32(target.size(o));
target.writeTo(o, out);
return;
}
if (type == FieldType.BOOL) {
out.writeBool(order, (Boolean) o);
} else if (type == FieldType.BYTES) {
byte[] bb = (byte[]) o;
out.writeBytes(order, ByteString.copyFrom(bb));
} else if (type == FieldType.DOUBLE) {
out.writeDouble(order, (Double) o);
} else if (type == FieldType.FIXED32) {
out.writeFixed32(order, (Integer) o);
} else if (type == FieldType.FIXED64) {
out.writeFixed64(order, (Long) o);
} else if (type == FieldType.FLOAT) {
out.writeFloat(order, (Float) o);
} else if (type == FieldType.INT32) {
out.writeInt32(order, (Integer) o);
} else if (type == FieldType.INT64) {
out.writeInt64(order, (Long) o);
} else if (type == FieldType.SFIXED32) {
out.writeSFixed32(order, (Integer) o);
} else if (type == FieldType.SFIXED64) {
out.writeSFixed64(order, (Long) o);
} else if (type == FieldType.SINT32) {
out.writeSInt32(order, (Integer) o);
} else if (type == FieldType.SINT64) {
out.writeSInt64(order, (Long) o);
} else if (type == FieldType.STRING) {
out.writeBytes(order, ByteString.copyFromUtf8(String.valueOf(o)));
} else if (type == FieldType.UINT32) {
out.writeUInt32(order, (Integer) o);
} else if (type == FieldType.UINT64) {
out.writeUInt64(order, (Long) o);
} else if (type == FieldType.ENUM) {
int value = 0;
if (o instanceof EnumReadable) {
value = ((EnumReadable) o).value();
} else if (o instanceof Enum) {
value = ((Enum) o).ordinal();
}
out.writeEnum(order, value);
}
}