@Override public synchronized void clearEncodedForm() { if (_encodedForm != null) { _section = decode(createNonEncodingRetainingSectionConstructor()); _encodedForm.dispose(); _encodedForm = null; _encodedSize = 0; } }
@Override public synchronized final long getEncodedSize() { encodeIfNecessary(); return _encodedSize; }
protected AbstractSection(final AbstractSection<T, S> otherAbstractSection) { _value = otherAbstractSection.getValue(); _section = otherAbstractSection._section; _encodedForm = otherAbstractSection.getEncodedForm(); _encodedSize = _encodedForm.remaining(); }
@Override public String toString() { if (_value == null) { return String.format("<Undecoded %s (%d bytes)>", getClass().getSimpleName(), _encodedSize); } else { return getValue().toString(); } }
private S decode(DescribedTypeConstructor<S> constructor) { try (QpidByteBuffer input = getEncodedForm()) { int originalPosition = input.position(); int describedByte = input.get(); if (describedByte != ValueHandler.DESCRIBED_TYPE) { throw new ConnectionScopedRuntimeException("Cannot decode section", new AmqpErrorException(AmqpError.DECODE_ERROR, "Not a described type.")); } ValueHandler handler = new ValueHandler(TYPE_REGISTRY); try { Object descriptor = handler.parse(input); return constructor.construct(descriptor, input, originalPosition, handler).construct(input, handler); } catch (AmqpErrorException e) { throw new ConnectionScopedRuntimeException("Cannot decode section", e); } } }
@Override public synchronized T getValue() { if(_value == null) { S section = decode(createNonEncodingRetainingSectionConstructor()); _value = section.getValue(); } return _value; }
protected AbstractSection(final S section) { _value = section.getValue(); _section = section; encodeIfNecessary(); }
@Override public synchronized final QpidByteBuffer getEncodedForm() { encodeIfNecessary(); return _encodedForm.duplicate(); }
@Override public synchronized void writeTo(final QpidByteBuffer dest) { encodeIfNecessary(); dest.putCopyOf(_encodedForm); }