public VPackSlice slice() { return new VPackSlice(buffer); }
public Message(final long id, final byte[] chunkBuffer) throws BufferUnderflowException, IndexOutOfBoundsException { super(); this.id = id; head = new VPackSlice(chunkBuffer); final int headSize = head.getByteSize(); if (chunkBuffer.length > headSize) { body = new VPackSlice(chunkBuffer, headSize); } else { body = null; } }
public VPackParser(final byte[] data, final int offset, final int features) { super(features); currentValue = new VPackSlice(data, offset); _currToken = null; objectIterators = new LinkedList<>(); arrayIterators = new LinkedList<>(); currentCompoundValue = new LinkedList<>(); }
private VPackSlice getFromCompactObject(final String attribute) throws VPackKeyTypeException, VPackNeedAttributeTranslatorException { for (final Iterator<Entry<String, VPackSlice>> iterator = objectIterator(); iterator.hasNext();) { final Entry<String, VPackSlice> next = iterator.next(); if (next.getKey().equals(attribute)) { return next.getValue(); } } // not found return new VPackSlice(); }
private VPackSlice getNth(final int index) { return new VPackSlice(vpack, start + getNthOffset(index)); }
private VPackSlice getNthKey(final int index) { return new VPackSlice(vpack, start + getNthOffset(index)); }
protected VPackSlice getCurrent() { return new VPackSlice(slice.getBuffer(), (int) current); }
private void sortObjectIndex(final int start, final List<Integer> offsets) throws VPackKeyTypeException, VPackNeedAttributeTranslatorException { final List<VPackBuilder.SortEntry> attributes = new ArrayList<VPackBuilder.SortEntry>(); for (final Integer offset : offsets) { attributes.add(new SortEntry(new VPackSlice(buffer, start + offset).makeKey(), offset)); } final Comparator<SortEntry> comparator = new Comparator<SortEntry>() { @Override public int compare(final SortEntry o1, final SortEntry o2) { return o1.slice.getAsString().compareTo(o2.slice.getAsString()); } }; Collections.sort(attributes, comparator); offsets.clear(); for (final SortEntry sortEntry : attributes) { offsets.add(sortEntry.offset); } }
/** * translates an integer key into a string, without checks */ protected VPackSlice translateUnchecked() { final VPackSlice result = attributeTranslator.translate(getAsInt()); return result != null ? result : new VPackSlice(); }
@SuppressWarnings("unchecked") @Override public VPackSlice serialize(final Object entity, final Options options) throws ArangoDBException { if (options.getType() == null) { options.type(entity.getClass()); } try { final VPackSlice vpack; final Class<? extends Object> type = entity.getClass(); final boolean serializeNullValues = options.isSerializeNullValues(); if (String.class.isAssignableFrom(type)) { vpack = vpackParser.fromJson((String) entity, serializeNullValues); } else if (options.isStringAsJson() && Iterable.class.isAssignableFrom(type)) { final Iterator<?> iterator = Iterable.class.cast(entity).iterator(); if (iterator.hasNext() && String.class.isAssignableFrom(iterator.next().getClass())) { vpack = vpackParser.fromJson((Iterable<String>) entity, serializeNullValues); } else { final ObjectMapper vp = serializeNullValues ? vpackMapperNull : vpackMapper; vpack = new VPackSlice(vp.writeValueAsBytes(entity)); } } else { final ObjectMapper vp = serializeNullValues ? vpackMapperNull : vpackMapper; vpack = new VPackSlice(vp.writeValueAsBytes(entity)); } return vpack; } catch (final JsonProcessingException e) { throw new ArangoDBException(e); } }
@Override public VPackSlice getValue() { return new VPackSlice(currentField.getBuffer(), currentField.getStart() + currentField.getByteSize()); }
final long offset = ieBase + index * offsetsize; final long keyIndex = NumberUtil.toLong(vpack, (int) (start + offset), offsetsize); final VPackSlice key = new VPackSlice(vpack, (int) (start + keyIndex)); int res = 0; if (key.isString()) { } else { result = new VPackSlice(); break; result = new VPackSlice(vpack, key.start + key.getByteSize()); break; result = new VPackSlice(); break; result = new VPackSlice(); break;
VPackSlice result = new VPackSlice(); for (long index = 0; index < n; index++) { final long offset = ieBase + index * offsetsize; final long keyIndex = NumberUtil.toLong(vpack, (int) (start + offset), offsetsize); final VPackSlice key = new VPackSlice(vpack, (int) (start + keyIndex)); if (key.isString()) { if (!key.isEqualString(attribute)) { result = new VPackSlice(); break; result = new VPackSlice(vpack, key.start + key.getByteSize()); break;
public VPackSlice valueAt(final int index) { if (!isObject()) { throw new VPackValueTypeException(ValueType.OBJECT); } final VPackSlice key = getNthKey(index); return new VPackSlice(vpack, key.start + key.getByteSize()); }
public Response buildResponse(final CloseableHttpResponse httpResponse) throws UnsupportedOperationException, IOException { final Response response = new Response(); response.setResponseCode(httpResponse.getStatusLine().getStatusCode()); final HttpEntity entity = httpResponse.getEntity(); if (entity != null && entity.getContent() != null) { if (contentType == Protocol.HTTP_VPACK) { final byte[] content = IOUtils.toByteArray(entity.getContent()); if (content.length > 0) { response.setBody(new VPackSlice(content)); } } else { final String content = IOUtils.toString(entity.getContent()); if (!content.isEmpty()) { response.setBody( util.serialize(content, new Options().stringAsJson(true).serializeNullValues(true))); } } } final Header[] headers = httpResponse.getAllHeaders(); final Map<String, String> meta = response.getMeta(); for (final Header header : headers) { meta.put(header.getName(), header.getValue()); } return response; }
@Override public VPackSlice deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException, JsonProcessingException { if (p instanceof VPackParser) { final VPackSlice vpack = ((VPackParser) p).getVPack(); // consume each element if (vpack.isArray() || vpack.isObject()) { for (int i = 0; i < vpack.size() + 1; i++) { p.nextToken(); } } return vpack; } return new VPackSlice(p.getBinaryValue()); } };
VPackSlice result = new VPackSlice(); if (head == 0x0a) { result = new VPackSlice(); } else if (head == 0x14) { final VPackSlice key = new VPackSlice(vpack, start + findDataOffset()); result = new VPackSlice(vpack, key.start + key.getByteSize()); } else { result = new VPackSlice(); result = new VPackSlice(vpack, key.start + key.getByteSize()); } else { result = new VPackSlice(); result = new VPackSlice();
/** * @return the offset for the nth member from a compact Array or Object type */ private int getNthOffsetFromCompact(final int index) { final long end = NumberUtil.readVariableValueLength(vpack, start + 1, false); final long n = NumberUtil.readVariableValueLength(vpack, (int) (start + end - 1), true); if (index >= n) { throw new IndexOutOfBoundsException(); } final byte head = head(); long offset = 1 + NumberUtil.getVariableValueLength(end); long current = 0; while (current != index) { final long byteSize = new VPackSlice(vpack, (int) (start + offset)).getByteSize(); offset += byteSize; if (head == 0x14) { offset += byteSize; } ++current; } return (int) offset; }
if (head <= 0x05) { final VPackSlice first = new VPackSlice(vpack, start + dataOffset); n = (end - dataOffset) / first.getByteSize(); } else if (offsetsize < 8) { dataOffset = findDataOffset(); offset = dataOffset + index * new VPackSlice(vpack, start + dataOffset).getByteSize(); } else { final long ieBase = end - n * offsetsize + index * offsetsize - (offsetsize == 8 ? 8 : 0);
final VPackSlice first = new VPackSlice(vpack, start + dataOffset); length = (end - dataOffset) / first.getByteSize(); } else if (offsetsize < 8) {