@Benchmark public Map<String, String> parseBytes() { return marshaller.parseBytes(serialized); }
static int sizeInBytes(Map<String, String> tagContext) { int sizeInBytes = 1; // VERSION for (Map.Entry<String, String> entry : tagContext.entrySet()) { sizeInBytes++; // TAG_FIELD_ID int keyLength = entry.getKey().length(); int valLength = entry.getValue().length(); if (keyLength > 16383 || valLength > 16383) return sizeInBytes; // stop here sizeInBytes += sizeOfLengthPrefixedString(keyLength); sizeInBytes += sizeOfLengthPrefixedString(valLength); } return sizeInBytes; }
@Benchmark public byte[] toBytes() { return marshaller.toBytes(context); }
@Override public byte[] toBytes(Map<String, String> tagContext) { if (tagContext == null) { throw new NullPointerException("tagContext == null"); // programming error } if (tagContext.isEmpty()) return EMPTY_BYTES; byte[] result = new byte[sizeInBytes(tagContext)]; Buffer bytes = new Buffer(result); bytes.writeByte(VERSION); for (Map.Entry<String, String> entry : tagContext.entrySet()) { bytes.writeByte(TAG_FIELD_ID); bytes.writeLengthPrefixed(entry.getKey()); bytes.writeLengthPrefixed(entry.getValue()); } return result; }
@Override public byte[] toBytes(Map<String, String> tagContext) { if (tagContext == null) { throw new NullPointerException("tagContext == null"); // programming error } if (tagContext.isEmpty()) return EMPTY_BYTES; byte[] result = new byte[sizeInBytes(tagContext)]; Buffer bytes = new Buffer(result); bytes.writeByte(VERSION); for (Map.Entry<String, String> entry : tagContext.entrySet()) { bytes.writeByte(TAG_FIELD_ID); bytes.writeLengthPrefixed(entry.getKey()); bytes.writeLengthPrefixed(entry.getValue()); } return result; }
static int sizeInBytes(Map<String, String> tagContext) { int sizeInBytes = 1; // VERSION for (Map.Entry<String, String> entry : tagContext.entrySet()) { sizeInBytes++; // TAG_FIELD_ID int keyLength = entry.getKey().length(); int valLength = entry.getValue().length(); if (keyLength > 16383 || valLength > 16383) return sizeInBytes; // stop here sizeInBytes += sizeOfLengthPrefixedString(keyLength); sizeInBytes += sizeOfLengthPrefixedString(valLength); } return sizeInBytes; }