/** * Builds and returns a {@code TraceOptions} with the desired options. * * @return a {@code TraceOptions} with the desired options. * @since 0.5 */ public TraceOptions build() { return fromByte(options); } }
/** * Returns a {@code TraceOptions} whose representation is copied from the {@code src} beginning at * the {@code srcOffset} offset. * * @param src the buffer where the representation of the {@code TraceOptions} is copied. * @param srcOffset the offset in the buffer where the representation of the {@code TraceOptions} * begins. * @return a {@code TraceOptions} whose representation is copied from the buffer. * @throws NullPointerException if {@code src} is null. * @throws IndexOutOfBoundsException if {@code srcOffset+TraceOptions.SIZE} is greater than {@code * src.length}. * @since 0.5 * @deprecated use {@link #fromByte(byte)}. */ @Deprecated public static TraceOptions fromBytes(byte[] src, int srcOffset) { Utils.checkIndex(srcOffset, src.length); return fromByte(src[srcOffset]); }
/** * Returns a {@code TraceOptions} built from a byte representation. * * <p>Equivalent with: * * <pre>{@code * TraceOptions.fromBytes(buffer, 0); * }</pre> * * @param buffer the representation of the {@code TraceOptions}. * @return a {@code TraceOptions} whose representation is given by the {@code buffer} parameter. * @throws NullPointerException if {@code buffer} is null. * @throws IllegalArgumentException if {@code buffer.length} is not {@link TraceOptions#SIZE}. * @since 0.5 * @deprecated use {@link #fromByte(byte)}. */ @Deprecated public static TraceOptions fromBytes(byte[] buffer) { Utils.checkNotNull(buffer, "buffer"); Utils.checkArgument( buffer.length == SIZE, "Invalid size: expected %s, got %s", SIZE, buffer.length); return fromByte(buffer[0]); }
@Test @SuppressWarnings("deprecation") public void deprecated_getBytes() { assertThat(TraceOptions.fromByte(FIRST_BYTE).getBytes()).isEqualTo(new byte[] {FIRST_BYTE}); }
@Test public void builder_FromOptions() { assertThat( TraceOptions.builder(TraceOptions.fromByte(THIRD_BYTE)) .setIsSampled(true) .build() .getOptions()) .isEqualTo(6 | 1); }
@Test public void traceOptions_EqualsAndHashCode() { EqualsTester tester = new EqualsTester(); tester.addEqualityGroup(TraceOptions.DEFAULT); tester.addEqualityGroup( TraceOptions.fromByte(SECOND_BYTE), TraceOptions.builder().setIsSampled(true).build()); tester.addEqualityGroup(TraceOptions.fromByte(FIRST_BYTE)); tester.testEquals(); }
throw new SpanContextParseException("Invalid input: truncated"); traceOptions = TraceOptions.fromByte(bytes[pos + ID_SIZE]);
@Test public void getOptions() { assertThat(TraceOptions.DEFAULT.getOptions()).isEqualTo(0); assertThat(TraceOptions.builder().setIsSampled(false).build().getOptions()).isEqualTo(0); assertThat(TraceOptions.builder().setIsSampled(true).build().getOptions()).isEqualTo(1); assertThat(TraceOptions.builder().setIsSampled(true).setIsSampled(false).build().getOptions()) .isEqualTo(0); assertThat(TraceOptions.fromByte(FIRST_BYTE).getOptions()).isEqualTo(-1); assertThat(TraceOptions.fromByte(SECOND_BYTE).getOptions()).isEqualTo(1); assertThat(TraceOptions.fromByte(THIRD_BYTE).getOptions()).isEqualTo(6); }
throw new SpanContextParseException("Invalid input: truncated"); traceOptions = TraceOptions.fromByte(bytes[pos + ID_SIZE]);