Java Code Examples for io.protostuff.Schema#isInitialized()

The following examples show how to use io.protostuff.Schema#isInitialized() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnsafeNioBufInput.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T mergeObject(T value, final Schema<T> schema) throws IOException {
    if (decodeNestedMessageAsGroup) {
        return mergeObjectEncodedAsGroup(value, schema);
    }

    final int length = readRawVarInt32();
    if (length < 0) {
        throw ProtocolException.negativeSize();
    }

    if (nioBuffer.remaining() < length) {
        throw ProtocolException.misreportedSize();
    }

    ByteBuffer dup = nioBuffer.slice();
    dup.limit(length);

    if (value == null) {
        value = schema.newMessage();
    }
    ByteBufferInput nestedInput = new ByteBufferInput(dup, false);
    schema.mergeFrom(nestedInput, value);
    if (!schema.isInitialized(value)) {
        throw new UninitializedMessageException(value, schema);
    }
    nestedInput.checkLastTagWas(0);

    nioBuffer.position(nioBuffer.position() + length);
    return value;
}
 
Example 2
Source File: UnsafeNioBufInput.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
private <T> T mergeObjectEncodedAsGroup(T value, final Schema<T> schema) throws IOException {
    if (value == null) {
        value = schema.newMessage();
    }
    schema.mergeFrom(this, value);
    if (!schema.isInitialized(value)) {
        throw new UninitializedMessageException(value, schema);
    }
    // handling is in #readFieldNumber
    checkLastTagWas(0);
    return value;
}
 
Example 3
Source File: NioBufInput.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T mergeObject(T value, final Schema<T> schema) throws IOException {
    if (decodeNestedMessageAsGroup)
        return mergeObjectEncodedAsGroup(value, schema);

    final int length = readRawVarInt32();
    if (length < 0) {
        throw ProtocolException.negativeSize();
    }

    if (nioBuffer.remaining() < length) {
        throw ProtocolException.misreportedSize();
    }

    ByteBuffer dup = nioBuffer.slice();
    dup.limit(length);

    // save old limit
    // final int oldLimit = this.limit;

    // this.limit = offset + length;

    if (value == null) {
        value = schema.newMessage();
    }
    ByteBufferInput nestedInput = new ByteBufferInput(dup, false);
    schema.mergeFrom(nestedInput, value);
    if (!schema.isInitialized(value)) {
        throw new UninitializedMessageException(value, schema);
    }
    nestedInput.checkLastTagWas(0);
    // checkLastTagWas(0);

    // restore old limit
    // this.limit = oldLimit;

    nioBuffer.position(nioBuffer.position() + length);
    return value;
}
 
Example 4
Source File: NioBufInput.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
private <T> T mergeObjectEncodedAsGroup(T value, final Schema<T> schema) throws IOException {
    if (value == null) {
        value = schema.newMessage();
    }
    schema.mergeFrom(this, value);
    if (!schema.isInitialized(value)) {
        throw new UninitializedMessageException(value, schema);
    }
    // handling is in #readFieldNumber
    checkLastTagWas(0);
    return value;
}
 
Example 5
Source File: UnsafeNioBufInput.java    From Jupiter with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T mergeObject(T value, final Schema<T> schema) throws IOException {
    if (decodeNestedMessageAsGroup) {
        return mergeObjectEncodedAsGroup(value, schema);
    }

    final int length = readRawVarInt32();
    if (length < 0) {
        throw ProtocolException.negativeSize();
    }

    if (nioBuffer.remaining() < length) {
        throw ProtocolException.misreportedSize();
    }

    ByteBuffer dup = nioBuffer.slice();
    dup.limit(length);

    if (value == null) {
        value = schema.newMessage();
    }
    ByteBufferInput nestedInput = new ByteBufferInput(dup, false);
    schema.mergeFrom(nestedInput, value);
    if (!schema.isInitialized(value)) {
        throw new UninitializedMessageException(value, schema);
    }
    nestedInput.checkLastTagWas(0);

    nioBuffer.position(nioBuffer.position() + length);
    return value;
}
 
Example 6
Source File: UnsafeNioBufInput.java    From Jupiter with Apache License 2.0 5 votes vote down vote up
private <T> T mergeObjectEncodedAsGroup(T value, final Schema<T> schema) throws IOException {
    if (value == null) {
        value = schema.newMessage();
    }
    schema.mergeFrom(this, value);
    if (!schema.isInitialized(value)) {
        throw new UninitializedMessageException(value, schema);
    }
    // handling is in #readFieldNumber
    checkLastTagWas(0);
    return value;
}
 
Example 7
Source File: NioBufInput.java    From Jupiter with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T mergeObject(T value, final Schema<T> schema) throws IOException {
    if (decodeNestedMessageAsGroup)
        return mergeObjectEncodedAsGroup(value, schema);

    final int length = readRawVarInt32();
    if (length < 0) {
        throw ProtocolException.negativeSize();
    }

    if (nioBuffer.remaining() < length) {
        throw ProtocolException.misreportedSize();
    }

    ByteBuffer dup = nioBuffer.slice();
    dup.limit(length);

    // save old limit
    // final int oldLimit = this.limit;

    // this.limit = offset + length;

    if (value == null) {
        value = schema.newMessage();
    }
    ByteBufferInput nestedInput = new ByteBufferInput(dup, false);
    schema.mergeFrom(nestedInput, value);
    if (!schema.isInitialized(value)) {
        throw new UninitializedMessageException(value, schema);
    }
    nestedInput.checkLastTagWas(0);
    // checkLastTagWas(0);

    // restore old limit
    // this.limit = oldLimit;

    nioBuffer.position(nioBuffer.position() + length);
    return value;
}
 
Example 8
Source File: NioBufInput.java    From Jupiter with Apache License 2.0 5 votes vote down vote up
private <T> T mergeObjectEncodedAsGroup(T value, final Schema<T> schema) throws IOException {
    if (value == null) {
        value = schema.newMessage();
    }
    schema.mergeFrom(this, value);
    if (!schema.isInitialized(value)) {
        throw new UninitializedMessageException(value, schema);
    }
    // handling is in #readFieldNumber
    checkLastTagWas(0);
    return value;
}