class StringCodec implements Codec<StringBuilder> {

  @Override
  public JaegerSpanContext extract(StringBuilder s) {
    if (s == null) {
      throw new EmptyTracerStateStringException();
    }
    String value = s.toString();
    if (!"".equals(value)) {
      String[] parts = value.split(":");
      if (parts.length != 4) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("MalformedTracerStateString: {}", value);
        }
        throw new MalformedTracerStateStringException(value);
      } else {
        String traceId = parts[0];
        if (traceId.length() <= 32 && traceId.length() >= 1) {
          return new JaegerSpanContext(high(traceId),
              (new BigInteger(traceId, 16)).longValue(),
              (new BigInteger(parts[1], 16)).longValue(),
              (new BigInteger(parts[2], 16)).longValue(),
              (new BigInteger(parts[3], 16)).byteValue());
        } else {
          throw new TraceIdOutOfBoundException(
              "Trace id [" + traceId + "] length is not within 1 and 32");
        }
      }
    } else {
      throw new EmptyTracerStateStringException();
    }
  }

}