• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017, OpenCensus Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.opencensus.tags.propagation;
18 
19 import io.opencensus.tags.Tag;
20 import io.opencensus.tags.TagContext;
21 import io.opencensus.tags.TagMetadata;
22 import io.opencensus.tags.TagMetadata.TagTtl;
23 
24 /**
25  * Object for serializing and deserializing {@link TagContext}s with the binary format.
26  *
27  * <p>See <a
28  * href="https://github.com/census-instrumentation/opencensus-specs/blob/master/encodings/BinaryEncoding.md#tag-context">opencensus-specs</a>
29  * for the specification of the cross-language binary serialization format.
30  *
31  * @since 0.8
32  */
33 public abstract class TagContextBinarySerializer {
34 
35   /**
36    * Serializes the {@code TagContext} into the on-the-wire representation.
37    *
38    * <p>This method should be the inverse of {@link #fromByteArray}.
39    *
40    * <p>{@link Tag}s that have a {@link TagMetadata} with {@link TagTtl#NO_PROPAGATION} will not be
41    * serialized.
42    *
43    * @param tags the {@code TagContext} to serialize.
44    * @return the on-the-wire representation of a {@code TagContext}.
45    * @throws TagContextSerializationException if the result would be larger than the maximum allowed
46    *     serialized size.
47    * @since 0.8
48    */
toByteArray(TagContext tags)49   public abstract byte[] toByteArray(TagContext tags) throws TagContextSerializationException;
50 
51   /**
52    * Creates a {@code TagContext} from the given on-the-wire encoded representation.
53    *
54    * <p>This method should be the inverse of {@link #toByteArray}.
55    *
56    * @param bytes on-the-wire representation of a {@code TagContext}.
57    * @return a {@code TagContext} deserialized from {@code bytes}.
58    * @throws TagContextDeserializationException if there is a parse error, the input contains
59    *     invalid tags, or the input is larger than the maximum allowed serialized size.
60    * @since 0.8
61    */
fromByteArray(byte[] bytes)62   public abstract TagContext fromByteArray(byte[] bytes) throws TagContextDeserializationException;
63 }
64