1 /* 2 * Copyright 2017 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 // Make sure that the PRI format string macros are defined 9 #ifndef __STDC_FORMAT_MACROS 10 #define __STDC_FORMAT_MACROS 11 #endif 12 13 #include <inttypes.h> 14 #include <stdarg.h> 15 16 #include "SkJSONWriter.h" 17 18 void SkJSONWriter::appendS64(int64_t value) { 19 this->beginValue(); 20 this->appendf("%" PRId64, value); 21 } 22 23 void SkJSONWriter::appendU64(uint64_t value) { 24 this->beginValue(); 25 this->appendf("%" PRIu64, value); 26 } 27 28 void SkJSONWriter::appendHexU64(uint64_t value) { 29 this->beginValue(); 30 this->appendf("\"0x%" PRIx64 "\"", value); 31 } 32 33 void SkJSONWriter::appendf(const char* fmt, ...) { 34 const int kBufferSize = 1024; 35 char buffer[kBufferSize]; 36 va_list argp; 37 va_start(argp, fmt); 38 #ifdef SK_BUILD_FOR_WIN 39 int length = _vsnprintf_s(buffer, kBufferSize, _TRUNCATE, fmt, argp); 40 #else 41 int length = vsnprintf(buffer, kBufferSize, fmt, argp); 42 #endif 43 SkASSERT(length >= 0 && length < kBufferSize); 44 va_end(argp); 45 this->write(buffer, length); 46 } 47