Java Code Examples for com.google.protobuf.CodedInputStream#readBool()
The following examples show how to use
com.google.protobuf.CodedInputStream#readBool() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Aspect.java From bazel with Apache License 2.0 | 6 votes |
@Override public Aspect deserialize(DeserializationContext context, CodedInputStream codedIn) throws SerializationException, IOException { AspectDescriptor aspectDescriptor = context.deserialize(codedIn); if (codedIn.readBool()) { return forNative( (NativeAspectClass) aspectDescriptor.getAspectClass(), aspectDescriptor.getParameters()); } else { AspectDefinition aspectDefinition = context.deserialize(codedIn); return forStarlark( (StarlarkAspectClass) aspectDescriptor.getAspectClass(), aspectDefinition, aspectDescriptor.getParameters()); } }
Example 2
Source File: Root.java From bazel with Apache License 2.0 | 6 votes |
@Override public Root deserialize(DeserializationContext context, CodedInputStream codedIn) throws SerializationException, IOException { if (codedIn.readBool()) { RootCodecDependencies codecDeps = context.getDependency(RootCodecDependencies.class); return codecDeps.likelyPopularRoot; } if (codedIn.readBool()) { Path path = context.deserialize(codedIn); return new PathRoot(path); } FileSystem fileSystem = context.deserialize(codedIn); return new AbsoluteRoot(fileSystem); }
Example 3
Source File: MultimapCodec.java From bazel with Apache License 2.0 | 6 votes |
@Override public ImmutableMultimap<K, V> deserialize( DeserializationContext context, CodedInputStream codedIn) throws SerializationException, IOException { ImmutableMultimap.Builder<K, V> result; if (codedIn.readBool()) { result = ImmutableListMultimap.builder(); } else { result = ImmutableSetMultimap.builder(); } int length = codedIn.readInt32(); for (int i = 0; i < length; i++) { K key = context.deserialize(codedIn); Collection<V> values = context.deserialize(codedIn); result.putAll(key, values); } return result.build(); }
Example 4
Source File: ImmutableMapCodec.java From bazel with Apache License 2.0 | 6 votes |
@Override public ImmutableMap<?, V> deserialize(DeserializationContext context, CodedInputStream codedIn) throws SerializationException, IOException { int length = codedIn.readInt32(); if (length < 0) { throw new SerializationException("Expected non-negative length: " + length); } ImmutableMap.Builder<?, V> builder; if (codedIn.readBool()) { builder = deserializeEntries(ImmutableSortedMap.naturalOrder(), length, context, codedIn); } else { builder = deserializeEntries( ImmutableMap.builderWithExpectedSize(length), length, context, codedIn); } try { return builder.build(); } catch (IllegalArgumentException e) { throw new SerializationException( "Duplicate keys during ImmutableMapCodec deserialization", e); } }
Example 5
Source File: ClassCodec.java From bazel with Apache License 2.0 | 5 votes |
@Override public Class<?> deserialize(DeserializationContext context, CodedInputStream codedIn) throws SerializationException, IOException { boolean isPrimitive = codedIn.readBool(); if (isPrimitive) { return PRIMITIVE_CLASS_INDEX_MAP.inverse().get(codedIn.readInt32()); } else { String className = context.deserialize(codedIn); try { return Class.forName(className); } catch (ClassNotFoundException e) { throw new SerializationException("Couldn't find class for " + className, e); } } }
Example 6
Source File: OptionalCodec.java From bazel with Apache License 2.0 | 5 votes |
@Override public Optional<?> deserialize(DeserializationContext context, CodedInputStream codedIn) throws SerializationException, IOException { if (!codedIn.readBool()) { return Optional.absent(); } return Optional.of(context.deserialize(codedIn)); }
Example 7
Source File: Optional8Codec.java From bazel with Apache License 2.0 | 5 votes |
@Override public Optional<?> deserialize(DeserializationContext context, CodedInputStream codedIn) throws SerializationException, IOException { if (!codedIn.readBool()) { return Optional.empty(); } return Optional.of(context.deserialize(codedIn)); }
Example 8
Source File: TrackManager.java From trekarta with GNU General Public License v3.0 | 4 votes |
private void readPoint(Track track, CodedInputStream input) throws IOException { int latitudeE6 = 0; int longitudeE6 = 0; boolean continuous = true; float altitude = Float.NaN; float speed = Float.NaN; float bearing = Float.NaN; float accuracy = Float.NaN; long timestamp = 0L; boolean done = false; while (!done) { int tag = input.readTag(); int field = WireFormat.getTagFieldNumber(tag); switch (field) { case 0: done = true; break; default: { throw new com.google.protobuf.InvalidProtocolBufferException("Unsupported proto field: " + tag); } case FIELD_POINT_LATITUDE: { latitudeE6 = input.readInt32(); break; } case FIELD_POINT_LONGITUDE: { longitudeE6 = input.readInt32(); break; } case FIELD_POINT_ALTITUDE: { altitude = input.readFloat(); break; } case FIELD_POINT_SPEED: { speed = input.readFloat(); break; } case FIELD_POINT_BEARING: { bearing = input.readFloat(); break; } case FIELD_POINT_ACCURACY: { accuracy = input.readFloat(); break; } case FIELD_POINT_TIMESTAMP: { timestamp = input.readUInt64(); break; } case FIELD_POINT_CONTINUOUS: { continuous = input.readBool(); break; } } } track.addPointFast(continuous, latitudeE6, longitudeE6, altitude, speed, bearing, accuracy, timestamp); }
Example 9
Source File: CodedConstant.java From jprotobuf with Apache License 2.0 | 4 votes |
/** * Read a field of any primitive type for immutable messages from a CodedInputStream. Enums, groups, and embedded * messages are not handled by this method. * * @param input The stream from which to read. * @param type Declared type of the field. * @param checkUtf8 When true, check that the input is valid utf8. * @return An object representing the field's value, of the exact type which would be returned by * {@link Message#getField(Descriptors.FieldDescriptor)} for this field. * @throws IOException Signals that an I/O exception has occurred. */ public static Object readPrimitiveField(CodedInputStream input, final WireFormat.FieldType type, boolean checkUtf8) throws IOException { switch (type) { case DOUBLE: return input.readDouble(); case FLOAT: return input.readFloat(); case INT64: return input.readInt64(); case UINT64: return input.readUInt64(); case INT32: return input.readInt32(); case FIXED64: return input.readFixed64(); case FIXED32: return input.readFixed32(); case BOOL: return input.readBool(); case STRING: if (checkUtf8) { return input.readStringRequireUtf8(); } else { return input.readString(); } case BYTES: return input.readByteArray(); case UINT32: return input.readUInt32(); case SFIXED32: return input.readSFixed32(); case SFIXED64: return input.readSFixed64(); case SINT32: return input.readSInt32(); case SINT64: return input.readSInt64(); case GROUP: throw new IllegalArgumentException("readPrimitiveField() cannot handle nested groups."); case MESSAGE: throw new IllegalArgumentException("readPrimitiveField() cannot handle embedded messages."); case ENUM: // We don't handle enums because we don't know what to do if the // value is not recognized. throw new IllegalArgumentException("readPrimitiveField() cannot handle enums."); } throw new RuntimeException("There is no way to get here, but the compiler thinks otherwise."); }
Example 10
Source File: BooleanCodec.java From bazel with Apache License 2.0 | 4 votes |
@Override public Boolean deserialize(DeserializationContext context, CodedInputStream codedIn) throws IOException { return codedIn.readBool(); }