• 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.TagContext;
20 
21 /**
22  * Object for serializing and deserializing {@link TagContext}s with the binary format.
23  *
24  * <p>See <a
25  * href="https://github.com/census-instrumentation/opencensus-specs/blob/master/encodings/BinaryEncoding.md#tag-context">opencensus-specs</a>
26  * for the specification of the cross-language binary serialization format.
27  *
28  * @since 0.8
29  */
30 public abstract class TagContextBinarySerializer {
31 
32   /**
33    * Serializes the {@code TagContext} into the on-the-wire representation.
34    *
35    * <p>This method should be the inverse of {@link #fromByteArray}.
36    *
37    * @param tags the {@code TagContext} to serialize.
38    * @return the on-the-wire representation of a {@code TagContext}.
39    * @throws TagContextSerializationException if the result would be larger than the maximum allowed
40    *     serialized size.
41    * @since 0.8
42    */
toByteArray(TagContext tags)43   public abstract byte[] toByteArray(TagContext tags) throws TagContextSerializationException;
44 
45   /**
46    * Creates a {@code TagContext} from the given on-the-wire encoded representation.
47    *
48    * <p>This method should be the inverse of {@link #toByteArray}.
49    *
50    * @param bytes on-the-wire representation of a {@code TagContext}.
51    * @return a {@code TagContext} deserialized from {@code bytes}.
52    * @throws TagContextDeserializationException if there is a parse error, the input contains
53    *     invalid tags, or the input is larger than the maximum allowed serialized size.
54    * @since 0.8
55    */
fromByteArray(byte[] bytes)56   public abstract TagContext fromByteArray(byte[] bytes) throws TagContextDeserializationException;
57 }
58