return fromWrappedByteArray(ctx, bytes, 0, bytes.length);
}
public static Object fromWrappedByteArray(SerializationContext ctx, byte[] bytes, int offset, int length) throws IOException {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes, offset, length);
CodedInputStream in = CodedInputStream.newInstance(bais);
String descriptorFullName = null;
int enumValue = -1;
byte[] messageBytes = null;
Object value = null;
int readTags = 0;
int tag;
while ((tag = in.readTag()) != 0) {
readTags++;
switch (tag) {
case wrappedDescriptorFullName << 3 | WireFormat.WIRETYPE_LENGTH_DELIMITED:
descriptorFullName = in.readString();
break;
case wrappedEnum << 3 | WireFormat.WIRETYPE_VARINT:
enumValue = in.readEnum();
break;
case wrappedMessageBytes << 3 | WireFormat.WIRETYPE_LENGTH_DELIMITED:
messageBytes = in.readBytes().toByteArray();
break;
case wrappedString << 3 | WireFormat.WIRETYPE_LENGTH_DELIMITED:
value = in.readString();
break;
case wrappedBytes << 3 | WireFormat.WIRETYPE_LENGTH_DELIMITED:
value = in.readBytes().toByteArray();
break;
case wrappedBool << 3 | WireFormat.WIRETYPE_VARINT:
value = in.readBool();
break;
case wrappedDouble << 3 | WireFormat.WIRETYPE_FIXED64:
value = in.readDouble();
break;
case wrappedFloat << 3 | WireFormat.WIRETYPE_FIXED32:
value = in.readFloat();
break;
case wrappedFixed32 << 3 | WireFormat.WIRETYPE_FIXED32:
value = in.readFixed32();
break;
case wrappedSFixed32 << 3 | WireFormat.WIRETYPE_FIXED32:
value = in.readSFixed32();
break;
case wrappedFixed64 << 3 | WireFormat.WIRETYPE_FIXED64:
value = in.readFixed64();
break;
case wrappedSFixed64 << 3 | WireFormat.WIRETYPE_FIXED64:
value = in.readSFixed64();
break;
case wrappedInt64 << 3 | WireFormat.WIRETYPE_VARINT:
value = in.readInt64();
break;
case wrappedUInt64 << 3 | WireFormat.WIRETYPE_VARINT:
value = in.readUInt64();
break;
case wrappedSInt64 << 3 | WireFormat.WIRETYPE_VARINT:
value = in.readSInt64();
break;
case wrappedInt32 << 3 | WireFormat.WIRETYPE_VARINT:
value = in.readInt32();
break;
case wrappedUInt32 << 3 | WireFormat.WIRETYPE_VARINT:
value = in.readUInt32();
break;
case wrappedSInt32 << 3 | WireFormat.WIRETYPE_VARINT:
value = in.readSInt32();
break;
default:
throw new IllegalStateException("Unexpected tag : " + tag);
}
}
if (value != null) {
if (readTags == 1) {
return value;
}
throw new IOException("Invalid message encoding.");
}
if (descriptorFullName == null || readTags != 2) {
throw new IOException("Invalid message encoding.");
}
if (messageBytes != null) {
MessageMarshaller marshaller = ctx.getMarshaller(descriptorFullName);
ByteArrayInputStream bais2 = new ByteArrayInputStream(messageBytes);
CodedInputStream in2 = CodedInputStream.newInstance(bais2);
ProtobufReaderImpl reader = new ProtobufReaderImpl(ctx);
return reader.read(in2, marshaller);
} else {
EnumEncoder<? extends Enum> enumEncoder = ctx.getEnumEncoder(descriptorFullName);
return enumEncoder.decode(enumValue);