static int write(OutputStream out, boolean withTags, ExtendedCell cell, byte[] value,
      byte[] tags) throws IOException {
      int valLen = value == null ? 0 : value.length;
      ByteBufferUtils.putInt(out, KeyValueUtil.keyLength(cell));// Key length
      ByteBufferUtils.putInt(out, valLen);// Value length
      int len = 2 * Bytes.SIZEOF_INT;
      len += writeFlatKey(cell, out);// Key
      if (valLen > 0) {
        out.write(value);// Value
      }
      len += valLen;
      if (withTags && tags != null) {
        // Write the tagsLength 2 bytes
        out.write((byte) (0xff & (tags.length >> 8)));
        out.write((byte) (0xff & tags.length));
        out.write(tags);
        len += KeyValue.TAGS_LENGTH_SIZE + tags.length;
      }
      return len;
    }
Made into a static method so as to reuse the logic within
ValueAndTagRewriteByteBufferExtendedCell
hbase-common/src/main/java/org/apache/hadoop/hbase/PrivateCellUtil.java