~ubuntu-branches/ubuntu/raring/protobuf/raring

« back to all changes in this revision

Viewing changes to java/src/main/java/com/google/protobuf/GeneratedMessageLite.java

  • Committer: Bazaar Package Importer
  • Author(s): Elliot Murphy
  • Date: 2010-06-08 17:29:12 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100608172912-nnd1hrkbv1u36pzl
Tags: 2.3.0-2ubuntu1
* Merge from Debian unstable.
* Remaining Ubuntu changes:
  - Don't use python2.4 (refreshed this patch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
303
303
        final ExtensionRegistryLite extensionRegistry,
304
304
        final int tag) throws IOException {
305
305
      final FieldSet<ExtensionDescriptor> extensions =
306
 
          internalGetResult().extensions;
 
306
          ((ExtendableMessage) internalGetResult()).extensions;
307
307
 
308
308
      final int wireType = WireFormat.getTagWireType(tag);
309
309
      final int fieldNumber = WireFormat.getTagFieldNumber(tag);
312
312
        extensionRegistry.findLiteExtensionByNumber(
313
313
            getDefaultInstanceForType(), fieldNumber);
314
314
 
315
 
      if (extension == null || wireType !=
316
 
            FieldSet.getWireFormatForFieldType(
317
 
                extension.descriptor.getLiteType(),
318
 
                extension.descriptor.isPacked())) {
319
 
        // Unknown field or wrong wire type.  Skip.
 
315
      boolean unknown = false;
 
316
      boolean packed = false;
 
317
      if (extension == null) {
 
318
        unknown = true;  // Unknown field.
 
319
      } else if (wireType == FieldSet.getWireFormatForFieldType(
 
320
                   extension.descriptor.getLiteType(),
 
321
                   false  /* isPacked */)) {
 
322
        packed = false;  // Normal, unpacked value.
 
323
      } else if (extension.descriptor.isRepeated &&
 
324
                 extension.descriptor.type.isPackable() &&
 
325
                 wireType == FieldSet.getWireFormatForFieldType(
 
326
                   extension.descriptor.getLiteType(),
 
327
                   true  /* isPacked */)) {
 
328
        packed = true;  // Packed value.
 
329
      } else {
 
330
        unknown = true;  // Wrong wire type.
 
331
      }
 
332
 
 
333
      if (unknown) {  // Unknown field or wrong wire type.  Skip.
320
334
        return input.skipField(tag);
321
335
      }
322
336
 
323
 
      if (extension.descriptor.isPacked()) {
 
337
      if (packed) {
324
338
        final int length = input.readRawVarint32();
325
339
        final int limit = input.pushLimit(length);
326
340
        if (extension.descriptor.getLiteType() == WireFormat.FieldType.ENUM) {
396
410
    }
397
411
 
398
412
    protected final void mergeExtensionFields(final MessageType other) {
399
 
      internalGetResult().extensions.mergeFrom(other.extensions);
 
413
      ((ExtendableMessage) internalGetResult()).extensions.mergeFrom(
 
414
          ((ExtendableMessage) other).extensions);
400
415
    }
401
416
  }
402
417
 
405
420
  /** For use by generated code only. */
406
421
  public static <ContainingType extends MessageLite, Type>
407
422
      GeneratedExtension<ContainingType, Type>
408
 
      newGeneratedExtension(
409
 
        final ContainingType containingTypeDefaultInstance,
410
 
        final Type defaultValue,
411
 
        final MessageLite messageDefaultInstance,
412
 
        final Internal.EnumLiteMap<?> enumTypeMap,
413
 
        final int number,
414
 
        final WireFormat.FieldType type) {
415
 
    return new GeneratedExtension<ContainingType, Type>(
416
 
      containingTypeDefaultInstance, defaultValue, messageDefaultInstance,
417
 
      new ExtensionDescriptor(enumTypeMap, number, type,
418
 
        false /* isRepeated */, false /* isPacked */));
419
 
  }
420
 
 
421
 
  /** For use by generated code only. */
422
 
  public static <ContainingType extends MessageLite, Type>
423
 
      GeneratedExtension<ContainingType, List<Type>>
424
 
      newRepeatedGeneratedExtension(
425
 
        final ContainingType containingTypeDefaultInstance,
426
 
        final MessageLite messageDefaultInstance,
427
 
        final Internal.EnumLiteMap<?> enumTypeMap,
428
 
        final int number,
429
 
        final WireFormat.FieldType type,
430
 
        final boolean isPacked) {
431
 
    return new GeneratedExtension<ContainingType, List<Type>>(
432
 
      containingTypeDefaultInstance, Collections.<Type>emptyList(),
433
 
      messageDefaultInstance,
434
 
      new ExtensionDescriptor(
435
 
        enumTypeMap, number, type, true /* isRepeated */, isPacked));
 
423
      newGeneratedExtension() {
 
424
    return new GeneratedExtension<ContainingType, Type>();
436
425
  }
437
426
 
438
427
  private static final class ExtensionDescriptor
500
489
   */
501
490
  public static final class GeneratedExtension<
502
491
      ContainingType extends MessageLite, Type> {
503
 
    private GeneratedExtension(
 
492
    // We can't always initialize a GeneratedExtension when we first construct
 
493
    // it due to initialization order difficulties (namely, the default
 
494
    // instances may not have been constructed yet).  So, we construct an
 
495
    // uninitialized GeneratedExtension once, then call internalInit() on it
 
496
    // later.  Generated code will always call internalInit() on all extensions
 
497
    // as part of the static initialization code, and internalInit() throws an
 
498
    // exception if called more than once, so this method is useless to users.
 
499
    private GeneratedExtension() {}
 
500
 
 
501
    private void internalInit(
504
502
        final ContainingType containingTypeDefaultInstance,
505
503
        final Type defaultValue,
506
504
        final MessageLite messageDefaultInstance,
511
509
      this.descriptor = descriptor;
512
510
    }
513
511
 
514
 
    private final ContainingType containingTypeDefaultInstance;
515
 
    private final Type defaultValue;
516
 
    private final MessageLite messageDefaultInstance;
517
 
    private final ExtensionDescriptor descriptor;
 
512
    /** For use by generated code only. */
 
513
    public void internalInitSingular(
 
514
        final ContainingType containingTypeDefaultInstance,
 
515
        final Type defaultValue,
 
516
        final MessageLite messageDefaultInstance,
 
517
        final Internal.EnumLiteMap<?> enumTypeMap,
 
518
        final int number,
 
519
        final WireFormat.FieldType type) {
 
520
      internalInit(
 
521
        containingTypeDefaultInstance, defaultValue, messageDefaultInstance,
 
522
        new ExtensionDescriptor(enumTypeMap, number, type,
 
523
          false /* isRepeated */, false /* isPacked */));
 
524
    }
 
525
 
 
526
    /** For use by generated code only. */
 
527
    public void internalInitRepeated(
 
528
        final ContainingType containingTypeDefaultInstance,
 
529
        final MessageLite messageDefaultInstance,
 
530
        final Internal.EnumLiteMap<?> enumTypeMap,
 
531
        final int number,
 
532
        final WireFormat.FieldType type,
 
533
        final boolean isPacked) {
 
534
      internalInit(
 
535
        containingTypeDefaultInstance, (Type) Collections.emptyList(),
 
536
        messageDefaultInstance,
 
537
        new ExtensionDescriptor(
 
538
          enumTypeMap, number, type, true /* isRepeated */, isPacked));
 
539
    }
 
540
 
 
541
    private ContainingType containingTypeDefaultInstance;
 
542
    private Type defaultValue;
 
543
    private MessageLite messageDefaultInstance;
 
544
    private ExtensionDescriptor descriptor;
518
545
 
519
546
    /**
520
547
     * Default instance of the type being extended, used to identify that type.