Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright 2010 Google Inc.
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  // http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
 package com.google.gwtorm.nosql;
 
 
Encodes a relation number in front of an object.
 
 public class RelationCodec<T> extends ProtobufCodec<T> {
  
Pop the field number from the stream and return it.

Parameters:
in the stream to pop the field number from. The caller is responsible for making sure the underlying stream had a mark set for at least 8 bytes so the tag can be examined, reset, and later read again during mergeFrom or decode.
Returns:
the field number of the relation.
Throws:
java.io.IOException the stream cannot be read.
 
   public static int peekId(CodedInputStream inthrows IOException {
     return in.readTag() >>> 3;
   }
 
   private final int fieldId;
   private final ProtobufCodec<T> objectCodec;
 
   public RelationCodec(int fieldIdProtobufCodec<T> objectCodec) {
     this. = fieldId;
     this. = objectCodec;
   }
 
   @Override
   public T newInstance() {
     return .newInstance();
   }
 
   @Override
   public int sizeof(T obj) {
     int sz = .sizeof(obj);
     return CodedOutputStream.computeTagSize(//
         + CodedOutputStream.computeRawVarint32Size(sz//
         + sz;
   }
 
   @Override
   public void encode(T objCodedOutputStream outthrows IOException {
     int sz = .sizeof(obj);
     out.writeRawVarint32(sz);
     .encode(objout);
   }
 
   @Override
   public void mergeFrom(CodedInputStream in, T objthrows IOException {
     boolean found = false;
     for (;;) {
       int tag = in.readTag();
       if (tag == 0) {
         if (found) {
           break;
         } else {
           // Reached EOF. But we require an object in our only field.
           throw new EOFException("Expected field " + );
         }
       }
 
       if ((tag >>> 3) == ) {
         if ((tag & 0x7) == ...getWireType()) {
           int sz = in.readRawVarint32();
           int oldLimit = in.pushLimit(sz);
           .mergeFrom(inobj);
           in.checkLastTagWas(0);
           in.popLimit(oldLimit);
           found = true;
         } else {
           throw new InvalidProtocolBufferException("Field " + 
               + " should be length delimited (wire type 2)");
         }
       } else {
         in.skipField(tag);
       }
    }
  }
New to GrepCode? Check out our FAQ X