// Copyright 2023 PingCAP, 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. #include #include #include namespace DB { template void formatHex(IteratorSrc src, IteratorDst dst, size_t num_bytes) { size_t src_pos = 0; size_t dst_pos = 0; for (; src_pos < num_bytes; ++src_pos) { writeHexByteLowercase(src[src_pos], &dst[dst_pos]); dst_pos += 2; } } void formatUUID(const UInt8 * src16, UInt8 * dst36) { formatHex(&src16[0], &dst36[0], 4); dst36[8] = '-'; formatHex(&src16[4], &dst36[9], 2); dst36[13] = '-'; formatHex(&src16[6], &dst36[14], 2); dst36[18] = '-'; formatHex(&src16[8], &dst36[19], 2); dst36[23] = '-'; formatHex(&src16[10], &dst36[24], 6); } /** Function used when byte ordering is important when parsing uuid * ex: When we create an UUID type */ void formatUUID(std::reverse_iterator src16, UInt8 * dst36) { formatHex(src16 + 8, &dst36[0], 4); dst36[8] = '-'; formatHex(src16 + 12, &dst36[9], 2); dst36[13] = '-'; formatHex(src16 + 14, &dst36[14], 2); dst36[18] = '-'; formatHex(src16, &dst36[19], 2); dst36[23] = '-'; formatHex(src16 + 2, &dst36[24], 6); } void writeException(const Exception & e, WriteBuffer & buf) { writeBinary(e.code(), buf); writeBinary(String(e.name()), buf); writeBinary(e.displayText(), buf); writeBinary(e.getStackTrace().toString(), buf); bool has_nested = e.nested() != nullptr; writeBinary(has_nested, buf); if (has_nested) writeException(Exception(*e.nested()), buf); } void writePointerHex(const void * ptr, WriteBuffer & buf) { writeString("0x", buf); char hex_str[2 * sizeof(ptr)]; writeHexUIntLowercase(reinterpret_cast(ptr), hex_str); buf.write(hex_str, 2 * sizeof(ptr)); } } // namespace DB