private void ensureDocumentIsAMsgPackMap(DirectBuffer document, String exceptionMsg) { final byte b = document.getByte(0); final MsgPackFormat format = MsgPackFormat.valueOf(b); if (format.getType() != MsgPackType.MAP && format.getType() != MsgPackType.NIL) { throw new MappingException(exceptionMsg); } } }
private void ensureDocumentIsAMsgPackMap(DirectBuffer document, String exceptionMsg) { final byte b = document.getByte(0); final MsgPackFormat format = MsgPackFormat.valueOf(b); if (format.getType() != MsgPackType.MAP && format.getType() != MsgPackType.NIL) { throw new MappingException(exceptionMsg); } } }
@Override public void wrap(DirectBuffer buff, int offset, int length) { final boolean documentIsNil = length == 0 || (length == 1 && buff.getByte(offset) == MsgPackCodes.NIL); if (documentIsNil) { buff = EMPTY_DOCUMENT; offset = 0; length = EMPTY_DOCUMENT.capacity(); } final byte firstByte = buff.getByte(offset); final MsgPackFormat format = MsgPackFormat.valueOf(firstByte); final boolean isValid = format.getType() == MsgPackType.MAP; if (!isValid) { throw new IllegalArgumentException( String.format( "Expected document to be a root level object, but was '%s'", format.getType().name())); } super.wrap(buff, offset, length); } }
@Override public void wrap(DirectBuffer buff, int offset, int length) { final boolean documentIsNil = length == 0 || (length == 1 && buff.getByte(offset) == MsgPackCodes.NIL); if (documentIsNil) { buff = EMPTY_DOCUMENT; offset = 0; length = EMPTY_DOCUMENT.capacity(); } final byte firstByte = buff.getByte(offset); final MsgPackFormat format = MsgPackFormat.valueOf(firstByte); final boolean isValid = format.getType() == MsgPackType.MAP; if (!isValid) { throw new IllegalArgumentException( String.format( "Expected document to be a root level object, but was '%s'", format.getType().name())); } super.wrap(buff, offset, length); } }