zipkin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-zipkin] adriancole commented on a change in pull request #2589: Makes SpanBytesDecoder work on ByteBuffer
Date Sun, 12 May 2019 11:11:03 GMT
adriancole commented on a change in pull request #2589: Makes SpanBytesDecoder work on ByteBuffer
URL: https://github.com/apache/incubator-zipkin/pull/2589#discussion_r283131757
 
 

 ##########
 File path: zipkin/src/main/java/zipkin2/codec/SpanBytesDecoder.java
 ##########
 @@ -35,123 +37,180 @@
 public enum SpanBytesDecoder implements BytesDecoder<Span> {
   /** Corresponds to the Zipkin v1 json format */
   JSON_V1 {
-    @Override
-    public Encoding encoding() {
+    @Override public Encoding encoding() {
       return Encoding.JSON;
     }
 
-    @Override
-    public boolean decode(byte[] bytes, Collection<Span> out) {
-      Span result = decodeOne(bytes);
+    @Override public boolean decode(byte[] span, Collection<Span> out) { // ex DependencyLinker
+      Span result = decodeOne(ReadBuffer.wrap(span, 0));
       if (result == null) return false;
       out.add(result);
       return true;
     }
 
-    @Override
-    public boolean decodeList(byte[] spans, Collection<Span> out) {
-      return new V1JsonSpanReader().readList(spans, out);
+    @Override public boolean decodeList(byte[] spans, Collection<Span> out) { // ex
getTrace
+      return new V1JsonSpanReader().readList(ReadBuffer.wrap(spans, 0), out);
     }
 
-    @Override
-    public Span decodeOne(byte[] span) {
-      V1Span v1 = JsonCodec.readOne(new V1JsonSpanReader(), span);
+    @Override public boolean decodeList(ByteBuffer spans, Collection<Span> out) {
+      return new V1JsonSpanReader().readList(ReadBuffer.wrapUnsafe(spans), out);
+    }
+
+    @Override @Nullable public Span decodeOne(byte[] span) {
+      return decodeOne(ReadBuffer.wrap(span, 0));
+    }
+
+    @Override @Nullable public Span decodeOne(ByteBuffer span) {
+      return decodeOne(ReadBuffer.wrapUnsafe(span));
+    }
+
+    Span decodeOne(ReadBuffer buffer) {
+      V1Span v1 = JsonCodec.readOne(new V1JsonSpanReader(), buffer);
       List<Span> out = new ArrayList<>(1);
       V1SpanConverter.create().convert(v1, out);
       return out.get(0);
     }
 
-    @Override
-    public List<Span> decodeList(byte[] spans) {
+    @Override public List<Span> decodeList(byte[] spans) {
+      return decodeList(this, spans);
+    }
+
+    @Override public List<Span> decodeList(ByteBuffer spans) {
       return decodeList(this, spans);
     }
   },
   /** Corresponds to the Zipkin v1 thrift format */
   THRIFT {
-    @Override
-    public Encoding encoding() {
+    @Override public Encoding encoding() {
       return Encoding.THRIFT;
     }
 
-    @Override
-    public boolean decode(byte[] span, Collection<Span> out) {
-      return ThriftCodec.read(span, out);
+    @Override public boolean decode(byte[] span, Collection<Span> out) { // ex DependencyLinker
+      return ThriftCodec.read(ReadBuffer.wrap(span, 0), out);
     }
 
-    @Override
-    public boolean decodeList(byte[] spans, Collection<Span> out) {
-      return ThriftCodec.readList(spans, out);
+    @Override public boolean decodeList(byte[] spans, Collection<Span> out) { // ex
getTrace
+      return ThriftCodec.readList(ReadBuffer.wrap(spans, 0), out);
     }
 
-    @Override
-    public Span decodeOne(byte[] span) {
-      return ThriftCodec.readOne(span);
+    @Override public boolean decodeList(ByteBuffer spans, Collection<Span> out) {
+      return ThriftCodec.readList(ReadBuffer.wrapUnsafe(spans), out);
     }
 
-    @Override
-    public List<Span> decodeList(byte[] spans) {
+    @Override @Nullable public Span decodeOne(byte[] span) {
+      return ThriftCodec.readOne(ReadBuffer.wrap(span, 0));
+    }
+
+    @Override @Nullable public Span decodeOne(ByteBuffer span) {
+      return ThriftCodec.readOne(ReadBuffer.wrapUnsafe(span));
+    }
+
+    @Override public List<Span> decodeList(byte[] spans) {
+      return decodeList(this, spans);
+    }
+
+    @Override public List<Span> decodeList(ByteBuffer spans) {
       return decodeList(this, spans);
     }
   },
   /** Corresponds to the Zipkin v2 json format */
   JSON_V2 {
-    @Override
-    public Encoding encoding() {
+    @Override public Encoding encoding() {
       return Encoding.JSON;
     }
 
-    @Override
-    public boolean decode(byte[] span, Collection<Span> out) { // ex decode span in
dependencies job
-      return JsonCodec.read(new V2SpanReader(), span, out);
+    @Override public boolean decode(byte[] span, Collection<Span> out) { // ex DependencyLinker
+      return JsonCodec.read(new V2SpanReader(), ReadBuffer.wrap(span, 0), out);
+    }
+
+    @Override public boolean decodeList(byte[] spans, Collection<Span> out) { // ex
getTrace
+      return JsonCodec.readList(new V2SpanReader(), ReadBuffer.wrap(spans, 0), out);
     }
 
-    @Override
-    public boolean decodeList(byte[] spans, Collection<Span> out) { // ex getTrace
-      return JsonCodec.readList(new V2SpanReader(), spans, out);
+    @Override public boolean decodeList(ByteBuffer spans, Collection<Span> out) {
+      return JsonCodec.readList(new V2SpanReader(), ReadBuffer.wrapUnsafe(spans), out);
     }
 
-    @Override
-    @Nullable
-    public Span decodeOne(byte[] span) {
-      return JsonCodec.readOne(new V2SpanReader(), span);
+    @Override @Nullable public Span decodeOne(byte[] span) {
+      return JsonCodec.readOne(new V2SpanReader(), ReadBuffer.wrap(span, 0));
     }
 
-    @Override
-    public List<Span> decodeList(byte[] spans) {
+    @Override @Nullable public Span decodeOne(ByteBuffer span) {
+      return JsonCodec.readOne(new V2SpanReader(), ReadBuffer.wrapUnsafe(span));
+    }
+
+    @Override public List<Span> decodeList(byte[] spans) {
+      return decodeList(this, spans);
+    }
+
+    @Override public List<Span> decodeList(ByteBuffer spans) {
       return decodeList(this, spans);
     }
   },
   PROTO3 {
-    @Override
-    public Encoding encoding() {
+    @Override public Encoding encoding() {
       return Encoding.PROTO3;
     }
 
-    @Override
-    public boolean decode(byte[] span, Collection<Span> out) { // ex decode span in
dependencies job
-      return Proto3Codec.read(span, out);
+    @Override public boolean decode(byte[] span, Collection<Span> out) { // ex DependencyLinker
+      return Proto3Codec.read(ReadBuffer.wrap(span, 0), out);
+    }
+
+    @Override public boolean decodeList(byte[] spans, Collection<Span> out) { // ex
getTrace
+      return Proto3Codec.readList(ReadBuffer.wrap(spans, 0), out);
+    }
+
+    @Override public boolean decodeList(ByteBuffer spans, Collection<Span> out) {
+      return Proto3Codec.readList(ReadBuffer.wrapUnsafe(spans), out);
     }
 
-    @Override
-    public boolean decodeList(byte[] spans, Collection<Span> out) { // ex getTrace
-      return Proto3Codec.readList(spans, out);
+    @Override @Nullable public Span decodeOne(byte[] span) {
+      return Proto3Codec.readOne(ReadBuffer.wrap(span, 0));
     }
 
-    @Override
-    @Nullable
-    public Span decodeOne(byte[] span) {
-      return Proto3Codec.readOne(span);
+    @Override @Nullable public Span decodeOne(ByteBuffer span) {
+      return Proto3Codec.readOne(ReadBuffer.wrapUnsafe(span));
     }
 
-    @Override
-    public List<Span> decodeList(byte[] spans) {
+    @Override public List<Span> decodeList(byte[] spans) {
+      return decodeList(this, spans);
+    }
+
+    @Override public List<Span> decodeList(ByteBuffer spans) {
       return decodeList(this, spans);
     }
   };
 
+  /**
+   * ByteBuffer implementation of {@link #decodeList(byte[])}.
+   *
+   * <p>Note: only use this when it is ok to modify the underlying {@link ByteBuffer#array()}.
+   */
+  public abstract boolean decodeList(ByteBuffer spans, Collection<Span> out);
 
 Review comment:
   adding the methods here allows us to not break the BytesDecoder interface, yet still allow
us the overloads for our builtin types

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message