private static void encodeSingleValue(LittleEndianOutput out, Object value) {
    if (value == EMPTY_REPRESENTATION) {
      out.writeByte(TYPE_EMPTY);
      out.writeLong(0L);
      return;
    }
    if (value instanceof Boolean) {
      Boolean bVal = ((Boolean) value);
      out.writeByte(TYPE_BOOLEAN);
      long longVal = bVal.booleanValue() ? 1L : 0L;
      out.writeLong(longVal);
      return;
    }
    if (value instanceof Double) {
      Double dVal = (Double) value;
      out.writeByte(TYPE_NUMBER);
      out.writeDouble(dVal.doubleValue());
      return;
    }
    if (value instanceof String) {
      String val = (String) value;
      out.writeByte(TYPE_STRING);
      StringUtil.writeUnicodeString(out, val);
      return;
    }
    if (value instanceof ErrorConstant) {
      ErrorConstant ecVal = (ErrorConstant) value;
      out.writeByte(TYPE_ERROR_CODE);
      long longVal = ecVal.getErrorCode();
      out.writeLong(longVal);
      return;
    }

    throw new IllegalStateException("Unexpected value type (" + value.getClass().getName() + "'");
  }