| 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 |
#include "src/utils/SkJSONWriter.h" |
| 9 |
|
| 10 |
#include <inttypes.h> |
| 11 |
#include <stdarg.h> |
| 12 |
#include <stdio.h> |
| 13 |
|
| 14 |
void SkJSONWriter::appendS64(int64_t value) { |
| 15 |
this->beginValue(); |
| 16 |
this->appendf("%" PRId64, value); |
| 17 |
} |
| 18 |
|
| 19 |
void SkJSONWriter::appendU64(uint64_t value) { |
| 20 |
this->beginValue(); |
| 21 |
this->appendf("%" PRIu64, value); |
| 22 |
} |
| 23 |
|
| 24 |
void SkJSONWriter::appendHexU64(uint64_t value) { |
| 25 |
this->beginValue(); |
| 26 |
this->appendf("\"0x%" PRIx64 "\"", value); |
| 27 |
} |
| 28 |
|
| 29 |
void SkJSONWriter::appendf(const char* fmt, ...) { |
| 30 |
const int kBufferSize = 1024; |
| 31 |
char buffer[kBufferSize]; |
| 32 |
va_list argp; |
| 33 |
va_start(argp, fmt); |
| 34 |
#ifdef SK_BUILD_FOR_WIN |
| 35 |
int length = _vsnprintf_s(buffer, kBufferSize, _TRUNCATE, fmt, argp); |
| 36 |
#else |
| 37 |
int length = vsnprintf(buffer, kBufferSize, fmt, argp); |
| 38 |
#endif |
| 39 |
SkASSERT(length >= 0 && length < kBufferSize); |
| 40 |
va_end(argp); |
| 41 |
this->write(buffer, length); |
| 42 |
} |