This benchmark attempts to measure performance of {@link
BinaryFormat#toBinaryValue(SpanContext)} then {@link BinaryFormat#fromBinaryValue(byte[])}.
438335
@Benchmark
  @BenchmarkMode(Mode.SampleTime)
  @OutputTimeUnit(TimeUnit.NANOSECONDS)
  public SpanContext toFromBinarySpanContext(Data data) throws SpanContextParseException {
    return data.binaryFormat.fromByteArray(data.binaryFormat.toByteArray(data.spanContext));
  }
1074681
@Benchmark
    @OperationsPerInvocation(20)
    public void benchmarkByteBuddy(Blackhole blackHole) {
        blackHole.consume(byteBuddyInstance.method(booleanValue));
        blackHole.consume(byteBuddyInstance.method(byteValue));
        blackHole.consume(byteBuddyInstance.method(shortValue));
        blackHole.consume(byteBuddyInstance.method(intValue));
        blackHole.consume(byteBuddyInstance.method(charValue));
        blackHole.consume(byteBuddyInstance.method(intValue));
        blackHole.consume(byteBuddyInstance.method(longValue));
        blackHole.consume(byteBuddyInstance.method(floatValue));
        blackHole.consume(byteBuddyInstance.method(doubleValue));
        blackHole.consume(byteBuddyInstance.method(stringValue));
        blackHole.consume(byteBuddyInstance.method(booleanValue, booleanValue, booleanValue));
        blackHole.consume(byteBuddyInstance.method(byteValue, byteValue, byteValue));
        blackHole.consume(byteBuddyInstance.method(shortValue, shortValue, shortValue));
        blackHole.consume(byteBuddyInstance.method(intValue, intValue, intValue));
        blackHole.consume(byteBuddyInstance.method(charValue, charValue, charValue));
        blackHole.consume(byteBuddyInstance.method(intValue, intValue, intValue));
        blackHole.consume(byteBuddyInstance.method(longValue, longValue, longValue));
        blackHole.consume(byteBuddyInstance.method(floatValue, floatValue, floatValue));
        blackHole.consume(byteBuddyInstance.method(doubleValue, doubleValue, doubleValue));
        blackHole.consume(byteBuddyInstance.method(stringValue, stringValue, stringValue));
    }
1223296
@Benchmark String charsToBitSet(int reps) {
    /*
     * This benchmark now measures the complete parsing of a char[] rather than
     * a single invocation of {@link BitSet#set}. However this fine because
     * it is intended to be a comparative benchmark.
     */
    for (int i = 0; i < reps; i++) {
      for (int n = 0; n < bitString.length; n++) {
        bitSet.set(n, bitString[n] == '1');
      }
    }
    return bitSet.toString();
  }
1258358
public byte[] toBinary(Object value, Object meta, boolean insertMeta) {
		return toBinary(value, meta, insertMeta, (input) -> {
			return mapper.writeValueAsBytes(input);
		}
966371
public MappingResult mappingResult(List<BinaryAnnotation> binaryAnnotations) {
        if (binaryAnnotations == null) {
            return new MappingResult();
        }

        List<String> componentTypes = new ArrayList<>();
        List<String> endpointTypes = new ArrayList<>();

        MappingResult.Builder mappingBuilder = MappingResult.builder();

        for (BinaryAnnotation binaryAnnotation: binaryAnnotations) {
            if (binaryAnnotation.getKey() == null) {
                continue;
            }

            BinaryAnnotationMapping mapping = mappingStorage.getKeyBasedMappings().get(binaryAnnotation.getKey());
            if (mapping != null && mapping.isIgnore()) {
                continue;
            }

            if (mapping == null || mapping.getProperty() == null) {
                // If no mapping, then just store property
                mappingBuilder.addProperty(new Property(binaryAnnotation.getKey(), binaryAnnotation.getValue(),
                        AnnotationTypeUtil.toPropertyType(binaryAnnotation.getType())));
            }

            if (mapping != null) {
                if (mapping.getComponentType() != null) {
                    componentTypes.add(mapping.getComponentType());
                }

                if (mapping.getEndpointType() != null) {
                    endpointTypes.add(mapping.getEndpointType());
                }

                if (mapping.getProperty() != null && !mapping.getProperty().isExclude()) {
                    String key = mapping.getProperty().getKey() != null ? mapping.getProperty().getKey() :
                            binaryAnnotation.getKey();
                    mappingBuilder.addProperty(new Property(key, binaryAnnotation.getValue(),
                            AnnotationTypeUtil.toPropertyType(binaryAnnotation.getType())));
                }
            }
        }

        if (!componentTypes.isEmpty()) {
            mappingBuilder.withComponentType(componentTypes.get(0));
        }
        if (!endpointTypes.isEmpty()) {
            mappingBuilder.withEndpointType(endpointTypes.get(0));
        }

        return mappingBuilder.build();
    }
381008
@Pure
	@Inline(value = "$2.valueOf($1.byteValue())", imported = Byte.class)
	public static Byte toByte(AtomicDouble number) {
		return Byte.valueOf(number.byteValue());
	}
1125760
public static ServerStats parseBytes(byte[] serialized)
      throws ServerStatsDeserializationException {
    final ByteBuffer bb = ByteBuffer.wrap(serialized);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    long serviceLatencyNs = 0L;
    long lbLatencyNs = 0L;
    byte traceOption = (byte) 0;

    // Check the version first.
    if (!bb.hasRemaining()) {
      throw new ServerStatsDeserializationException("Serialized ServerStats buffer is empty");
    }
    byte version = bb.get();

    if (version > CURRENT_VERSION || version < 0) {
      throw new ServerStatsDeserializationException("Invalid ServerStats version: " + version);
    }

    while (bb.hasRemaining()) {
      ServerStatsFieldEnums.Id id = ServerStatsFieldEnums.Id.valueOf((int) bb.get() & 0xFF);
      if (id == null) {
        // Skip remaining;
        bb.position(bb.limit());
      } else {
        switch (id) {
          case SERVER_STATS_LB_LATENCY_ID:
            lbLatencyNs = bb.getLong();
            break;
          case SERVER_STATS_SERVICE_LATENCY_ID:
            serviceLatencyNs = bb.getLong();
            break;
          case SERVER_STATS_TRACE_OPTION_ID:
            traceOption = bb.get();
            break;
        }
      }
    }
    try {
      return ServerStats.create(lbLatencyNs, serviceLatencyNs, traceOption);
    } catch (IllegalArgumentException e) {
      throw new ServerStatsDeserializationException(
          "Serialized ServiceStats contains invalid values: " + e.getMessage());
    }
  }
7912
public static byte[] parseBinary(InputStream inputStream, final int size) throws IOException {
        byte value[] = new byte[size];
        int i = value.length;
        while (i != 0) {
            i -= inputStream.read(value, value.length - i, i);
        }

        return value;
    }
1164480
@Override
  public <T extends BinaryReadHandle> T read(String uri, T contentHandle, long start, long length) {
    return read(uri, null, contentHandle, null, start, length, null);
  }
796834
@Benchmark
  @BenchmarkMode(Mode.SampleTime)
  @OutputTimeUnit(TimeUnit.NANOSECONDS)
  public byte[][] marshalOld() {
    Metadata m = new Metadata();
    m.put(
        GrpcUtil.MESSAGE_ACCEPT_ENCODING_KEY,
        InternalDecompressorRegistry.getRawAdvertisedMessageEncodings(reg));
    return TransportFrameUtil.toHttp2Headers(m);
  }
445253
public static int fromBinary(boolean[] binary)
    {
        Check.notNull(binary);

        int number = 0;
        for (final boolean current : binary)
        {
            number = number << 1 | boolToInt(current);
        }
        return number;
    }
466102
function isFbxFormatBinary( buffer ) {

		var CORRECT = 'Kaydara FBX Binary  \0';

		return buffer.byteLength >= CORRECT.length && CORRECT === convertArrayBufferToString( buffer, 0, CORRECT.length );

	}
683495
byte []readBinary()
    throws IOException
  {
    TempOutputStream tos = new TempOutputStream();
    
    while (true) {
      int ch = read();
      int len;
    
      switch (ch) {
      default:
        _peek = ch;
        return tos.toByteArray();
      
      case 0x20: case 0x21: case 0x22: case 0x23:
      case 0x24: case 0x25: case 0x26: case 0x27:
      case 0x28: case 0x29: case 0x2a: case 0x2b:
      case 0x2c: case 0x2d: case 0x2e: case 0x2f:
        len = ch - 0x20;
        readBinary(tos, len);
        return tos.toByteArray();
      
      case 0x34: case 0x35: case 0x36: case 0x37:
        len = ((ch - 0x34) << 8) + read();
        readBinary(tos, len);
        return tos.toByteArray();
        
      case 'B':
        len = readShort();
        readBinary(tos, len);
        return tos.toByteArray();
        
      case 'A':
        len = readShort();
        readBinary(tos, len);
        break;
      }
    }
  }
52572
protected ExternalBinaryValue binaryFor( File file ) {
        try {
            return createBinaryValue(file);
        } catch (RuntimeException e) {
            throw e;
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }
248234
@Override
	public BinaryRow baseRowToBinary(BaseRow row) {
		if (row instanceof BinaryRow) {
			return (BinaryRow) row;
		}
		BinaryRow binaryRow = new BinaryRow(types.length);
		BinaryRowWriter writer = new BinaryRowWriter(binaryRow);
		writer.writeHeader(row.getHeader());
		for (int i = 0; i < types.length; i++) {
			if (row.isNullAt(i)) {
				writer.setNullAt(i);
			} else {
				BinaryWriter.write(writer, i, TypeGetterSetters.get(row, i, types[i]), types[i]);
			}
		}
		writer.complete();
		return binaryRow;
	}
825472
@Override
    public final Integer fromBytes(Class targetClass, byte[] b)
    {
        if (b == null)
        {
            return null;
        }
        return ((b[0] << 24) + ((b[1] & 0xFF) << 16) + ((b[2] & 0xFF) << 8) + (b[3] & 0xFF));
    }
1065394
private BinaryResponse readBinaryResponse() throws IOException {
		BinaryResponse response = new BinaryResponse();
		response.setResponseCode(connection.getResponseCode());
		response.setResponseMessage(connection.getResponseMessage());
		response.setHeaders(connection.getHeaderFields());
		try {
			response.setBinaryBody(getBinaryFromStream(connection.getInputStream()));
		} catch (IOException e) {
			response.setBinaryBody(getBinaryFromStream(connection.getErrorStream()));
		}
		return response;
	}