/*
 * Copyright 2017, Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.opencensus.tags;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.annotation.concurrent.Immutable;

/** Object for serializing and deserializing {@link TagContext}s. */
public abstract class TagContextSerializer {
  private static final TagContextSerializer NOOP_TAG_CONTEXT_SERIALIZER =
      new NoopTagContextSerializer();

  /**
   * Serializes the {@code TagContext} into the on-the-wire representation.
   *
   * <p>This method should be the inverse of {@link #deserialize}.
   *
   * @param tags the {@code TagContext} to serialize.
   * @param output the {@link OutputStream} to write the serialized tags to.
   */
  public abstract void serialize(TagContext tags, OutputStream output) throws IOException;

  /**
   * Creates a {@code TagContext} from the given on-the-wire encoded representation.
   *
   * <p>This method should be the inverse of {@link #serialize}.
   *
   * @param input on-the-wire representation of a {@code TagContext}.
   * @return a {@code TagContext} deserialized from {@code input}.
   */
  public abstract TagContext deserialize(InputStream input) throws IOException;

  /**
   * Returns a {@code TagContextSerializer} that serializes all {@code TagContext}s to zero bytes
   * and deserializes all inputs to empty {@code TagContext}s.
   */
  static TagContextSerializer getNoopTagContextSerializer() {
    return NOOP_TAG_CONTEXT_SERIALIZER;
  }

  @Immutable
  private static final class NoopTagContextSerializer extends TagContextSerializer {

    @Override
    public void serialize(TagContext tags, OutputStream output) throws IOException {}

    @Override
    public TagContext deserialize(InputStream input) throws IOException {
      return TagContext.getNoopTagContext();
    }
  }
}

@@ -1259,16 +1259,109 @@
 ags to.%0A
+   * @throws IOException if there is an %7B@code IOException%7D while writing to %7B@code output%7D.%0A
    */%0A  
@@ -1749,24 +1749,144 @@
 ode input%7D.%0A
+   * @throws IOException if there is a parse error or an %7B@code IOException%7D while reading from%0A   *     %7B@code input%7D.%0A
    */%0A  publ

Document exceptions thrown by serialization methods.