Exemplo n.º 1
0
 /**
  * Since this coder uses elementCoders.get(index) and coders that are known to run in constant
  * time, we defer the return value to that coder.
  */
 @Override
 public boolean isRegisterByteSizeObserverCheap(RawUnionValue union, Context context) {
   int index = getIndexForEncoding(union);
   @SuppressWarnings("unchecked")
   Coder<Object> coder = (Coder<Object>) elementCoders.get(index);
   return coder.isRegisterByteSizeObserverCheap(union.getValue(), context);
 }
Exemplo n.º 2
0
 /** Notifies ElementByteSizeObserver about the byte size of the encoded value using this coder. */
 @Override
 public void registerByteSizeObserver(
     RawUnionValue union, ElementByteSizeObserver observer, Context context) throws Exception {
   int index = getIndexForEncoding(union);
   // Write out the union tag.
   observer.update(VarInt.getLength(index));
   // Write out the actual value.
   @SuppressWarnings("unchecked")
   Coder<Object> coder = (Coder<Object>) elementCoders.get(index);
   coder.registerByteSizeObserver(union.getValue(), observer, context);
 }
Exemplo n.º 3
0
  @SuppressWarnings("unchecked")
  @Override
  public void encode(RawUnionValue union, OutputStream outStream, Context context)
      throws IOException, CoderException {
    int index = getIndexForEncoding(union);
    // Write out the union tag.
    VarInt.encode(index, outStream);

    // Write out the actual value.
    Coder<Object> coder = (Coder<Object>) elementCoders.get(index);
    coder.encode(union.getValue(), outStream, context);
  }