10e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// Protocol Buffers - Google's data interchange format 20e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// Copyright 2013 Google Inc. All rights reserved. 3b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer// https://developers.google.com/protocol-buffers/ 40e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// 50e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// Redistribution and use in source and binary forms, with or without 60e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// modification, are permitted provided that the following conditions are 70e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// met: 80e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// 90e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// * Redistributions of source code must retain the above copyright 100e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// notice, this list of conditions and the following disclaimer. 110e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// * Redistributions in binary form must reproduce the above 120e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// copyright notice, this list of conditions and the following disclaimer 130e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// in the documentation and/or other materials provided with the 140e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// distribution. 150e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// * Neither the name of Google Inc. nor the names of its 160e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// contributors may be used to endorse or promote products derived from 170e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// this software without specific prior written permission. 180e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// 190e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 200e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 210e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 220e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 230e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 240e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 250e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 260e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 270e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 280e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 290e055f079f53b07de3705838a7b4742ce56839f8Brian Duff// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 300e055f079f53b07de3705838a7b4742ce56839f8Brian Duff 310e055f079f53b07de3705838a7b4742ce56839f8Brian Duffpackage com.google.protobuf.nano; 320e055f079f53b07de3705838a7b4742ce56839f8Brian Duff 33cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveiraimport java.io.IOException; 34ccc48faf20dbf3b3cddcffe78d198876d543529bBrian Duffimport java.util.Arrays; 35ccc48faf20dbf3b3cddcffe78d198876d543529bBrian Duff 360e055f079f53b07de3705838a7b4742ce56839f8Brian Duff/** 37cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira * Stores unknown fields. These might be extensions or fields that the generated 38cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira * API doesn't know about yet. 390e055f079f53b07de3705838a7b4742ce56839f8Brian Duff * 400e055f079f53b07de3705838a7b4742ce56839f8Brian Duff * @author bduff@google.com (Brian Duff) 410e055f079f53b07de3705838a7b4742ce56839f8Brian Duff */ 42cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveirafinal class UnknownFieldData { 43ccc48faf20dbf3b3cddcffe78d198876d543529bBrian Duff 44cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira final int tag; 45bcf45045f229edab8c2589c1f561e7b7495a763bBrian Duff /** 46bcf45045f229edab8c2589c1f561e7b7495a763bBrian Duff * Important: this should be treated as immutable, even though it's possible 47bcf45045f229edab8c2589c1f561e7b7495a763bBrian Duff * to change the array values. 48bcf45045f229edab8c2589c1f561e7b7495a763bBrian Duff */ 49cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira final byte[] bytes; 500e055f079f53b07de3705838a7b4742ce56839f8Brian Duff 51cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira UnknownFieldData(int tag, byte[] bytes) { 52cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira this.tag = tag; 53cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira this.bytes = bytes; 54cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira } 55ccc48faf20dbf3b3cddcffe78d198876d543529bBrian Duff 56cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira int computeSerializedSize() { 57cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira int size = 0; 58cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira size += CodedOutputByteBufferNano.computeRawVarint32Size(tag); 59cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira size += bytes.length; 60cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira return size; 61ccc48faf20dbf3b3cddcffe78d198876d543529bBrian Duff } 62cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira 63cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira void writeTo(CodedOutputByteBufferNano output) throws IOException { 64cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira output.writeRawVarint32(tag); 65cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira output.writeRawBytes(bytes); 66ccc48faf20dbf3b3cddcffe78d198876d543529bBrian Duff } 67ccc48faf20dbf3b3cddcffe78d198876d543529bBrian Duff 68cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira @Override 69cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira public boolean equals(Object o) { 70cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira if (o == this) { 71cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira return true; 72cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira } 73cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira if (!(o instanceof UnknownFieldData)) { 74cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira return false; 75cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira } 76ccc48faf20dbf3b3cddcffe78d198876d543529bBrian Duff 77cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira UnknownFieldData other = (UnknownFieldData) o; 78cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira return tag == other.tag && Arrays.equals(bytes, other.bytes); 79cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira } 80cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira 81cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira @Override 82cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira public int hashCode() { 83cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira int result = 17; 84cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira result = 31 * result + tag; 85cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira result = 31 * result + Arrays.hashCode(bytes); 86cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira return result; 87cf1b416ae1327a26dd53a691fc1b3e30eec8e6a6Juan Silveira } 880e055f079f53b07de3705838a7b4742ce56839f8Brian Duff} 89