本文整理匯總了Java中com.google.protobuf.CodedOutputStream.writeSInt32方法的典型用法代碼示例。如果您正苦於以下問題:Java CodedOutputStream.writeSInt32方法的具體用法?Java CodedOutputStream.writeSInt32怎麽用?Java CodedOutputStream.writeSInt32使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.protobuf.CodedOutputStream
的用法示例。
在下文中一共展示了CodedOutputStream.writeSInt32方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeObject
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
/**
* Write object to byte array by {@link FieldType}.
*
* @param out the out
* @param order the order
* @param type the type
* @param o the o
* @param list the list
* @throws IOException Signals that an I/O exception has occurred.
*/
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);
}
}
示例2: writeTo
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
private void writeTo(FieldInfo fieldInfo, Object value, CodedOutputStream out) throws IOException {
FieldType fieldType = fieldInfo.getFieldType();
int order = fieldInfo.getOrder();
if (value instanceof List) {
// if check list
CodedConstant.writeToList(out, order, fieldType, (List) value);
return;
}
switch (fieldType) {
case DOUBLE:
out.writeDouble(order, (Double) value);
break;
case BYTES:
ByteString bytes = ByteString.copyFrom((byte[]) value);
out.writeBytes(order, bytes);
break;
case STRING:
ByteString string = ByteString.copyFromUtf8(value.toString());
out.writeBytes(order, string);
break;
case BOOL:
out.writeBool(order, (Boolean) value);
break;
case FIXED32:
out.writeFixed32(order, (Integer) value);
break;
case SFIXED32:
out.writeSFixed32(order, (Integer) value);
break;
case SINT32:
out.writeSInt32(order, (Integer) value);
break;
case INT32:
out.writeInt32(order, (Integer) value);
break;
case UINT32:
out.writeUInt32(order, (Integer) value);
break;
case FIXED64:
out.writeFixed64(order, (Long) value);
break;
case SFIXED64:
out.writeSFixed64(order, (Long) value);
break;
case SINT64:
out.writeSInt64(order, (Long) value);
break;
case INT64:
out.writeInt64(order, (Long) value);
break;
case UINT64:
out.writeUInt64(order, (Long) value);
break;
case ENUM:
int i;
i = getEnumValue(value);
out.writeEnum(order, i);
break;
case FLOAT:
out.writeFloat(order, (Float) value);
break;
case OBJECT:
Class c = value.getClass();
ReflectiveCodec codec = new ReflectiveCodec(c);
out.writeRawVarint32(CodedConstant.makeTag(order, WireFormat.WIRETYPE_LENGTH_DELIMITED));
out.writeRawVarint32(codec.size(value));
codec.writeTo(value, out);
break;
default:
throw new IOException("Unknown field type on field '" + fieldInfo.getField().getName() + "'");
}
}
示例3: 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);
}
}