// Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.protobuf; /** * RawMessageInfo stores the same amount of information as {@link MessageInfo} but in a more compact * format. */ @CheckReturnValue final class RawMessageInfo implements MessageInfo { private final MessageLite defaultInstance; /** * The compact format packs everything in a String object and a Object[] array. The String object * is encoded with field number, field type, hasbits offset, oneof index, etc., whereas the * Object[] array contains field references, class references, instance references, etc. * *
The String object encodes a sequence of integers into UTF-16 characters. For each int, it * will be encoding into 1 to 3 UTF-16 characters depending on its unsigned value: * *
Note that we don't use UTF-16 surrogate pairs [0xD800 - 0xDFFF] because they have to come in * pairs to form a valid UTF-16char sequence and don't help us encode values more efficiently. * *
The integer sequence encoded in the String object has the following layout: * *
Each field entry starts with a field number and the field type: * *
The Object[] array has 3 sections: * *
In the Object[] array, field entries are ordered in the same way as field entries in the * String object. The size of each entry is determined by the field type. * *
In order to read the field info from this compact format, a reader needs to progress through * the String object and the Object[] array simultaneously. */ private final String info; private final Object[] objects; private final int flags; RawMessageInfo(MessageLite defaultInstance, String info, Object[] objects) { this.defaultInstance = defaultInstance; this.info = info; this.objects = objects; int position = 0; int value = (int) info.charAt(position++); if (value < 0xD800) { flags = value; } else { int result = value & 0x1FFF; int shift = 13; while ((value = info.charAt(position++)) >= 0xD800) { result |= (value & 0x1FFF) << shift; shift += 13; } flags = result | (value << shift); } } String getStringInfo() { return info; } Object[] getObjects() { return objects; } @Override public MessageLite getDefaultInstance() { return defaultInstance; } @Override public ProtoSyntax getSyntax() { return (flags & 0x1) == 0x1 ? ProtoSyntax.PROTO2 : ProtoSyntax.PROTO3; } @Override public boolean isMessageSetWireFormat() { return (flags & 0x2) == 0x2; } }