public static CodedOutputStream outputStreamFromByteRange(PositionedByteRange dst) {
    return CodedOutputStream.newInstance(dst.getBytes(), dst.getOffset() + dst.getPosition(),
      dst.getRemaining());
  }
Create a {@link CodedOutputStream} from a {@link PositionedByteRange}. Be sure to update
{@code dst}'s position after writing to the stream.
<p/>
For example:

<pre>
CodedOutputStream os = outputStreamFromByteRange(dst);
int before = os.spaceLeft(), after, written;
val.writeTo(os);
after = os.spaceLeft();
written = before - after;
dst.setPosition(dst.getPosition() + written);
</pre>
hbase-examples/src/main/java/org/apache/hadoop/hbase/types/PBType.java