com.google.protobuf.CodedInputStream# readBool ( ) 源码实例Demo

下面列出了com.google.protobuf.CodedInputStream# readBool ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: bazel   文件: Aspect.java

@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());
  }
}
 
源代码2 项目: bazel   文件: Root.java

@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);
}
 
源代码3 项目: bazel   文件: MultimapCodec.java

@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();
}
 
源代码4 项目: bazel   文件: ImmutableMapCodec.java

@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);
  }
}
 
源代码5 项目: bazel   文件: ClassCodec.java

@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);
    }
  }
}
 
源代码6 项目: bazel   文件: OptionalCodec.java

@Override
public Optional<?> deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  if (!codedIn.readBool()) {
    return Optional.absent();
  }
  return Optional.of(context.deserialize(codedIn));
}
 
源代码7 项目: bazel   文件: Optional8Codec.java

@Override
public Optional<?> deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  if (!codedIn.readBool()) {
    return Optional.empty();
  }
  return Optional.of(context.deserialize(codedIn));
}
 
源代码8 项目: trekarta   文件: TrackManager.java

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);
}
 
源代码9 项目: jprotobuf   文件: CodedConstant.java

/**
 * 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.");
}
 
源代码10 项目: bazel   文件: BooleanCodec.java

@Override
public Boolean deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws IOException {
  return codedIn.readBool();
}