| 1 |
/** |
| 2 |
* A position in the Writer's output, used to roll back speculative writes. |
| 3 |
*/ |
| 4 |
interface Mark { |
| 5 |
readonly size: number; |
| 6 |
readonly depth: number; |
| 7 |
} |
| 8 |
/** |
| 9 |
* A writer for the protobuf text format. |
| 10 |
* |
| 11 |
* The Writer owns layout: indentation, line breaks, and braces. Its output |
| 12 |
* matches the default formatting of txtpbfmt and the multi-line output of |
| 13 |
* protobuf-go: two-space indentation, `name: value` with a single space after |
| 14 |
* the colon, submessages as `name: {` with the body indented and `}` aligned |
| 15 |
* under the field name, and a trailing newline. It never inserts the randomized |
| 16 |
* extra spaces that protobuf-go adds to discourage parsing its output as |
| 17 |
* canonical. |
| 18 |
* |
| 19 |
* Output accumulates into a single buffer of lines, so a deep tree costs no |
| 20 |
* more than the bytes it prints. To decide between `name: {}` and an indented |
| 21 |
* block, the caller renders the body, then rolls back with mark()/reset() if it |
| 22 |
* turned out empty — an O(1) decision that needs no separate child buffer. |
| 23 |
*/ |
| 24 |
export declare class Writer { |
| 25 |
private readonly chunks; |
| 26 |
private depth; |
| 27 |
/** |
| 28 |
* Write a scalar field: `<indent>name: value` followed by a newline. |
| 29 |
*/ |
| 30 |
scalar(name: string, value: string): void; |
| 31 |
/** |
| 32 |
* Write an empty message field: `<indent>name: {}` followed by a newline. |
| 33 |
*/ |
| 34 |
emptyMessage(name: string): void; |
| 35 |
/** |
| 36 |
* Open a message field: `<indent>name: {` followed by a newline, then indent |
| 37 |
* the body. Close it with end(). |
| 38 |
*/ |
| 39 |
openMessage(name: string): void; |
| 40 |
/** |
| 41 |
* Close a message opened with openMessage(): outdent and write `<indent>}` |
| 42 |
* followed by a newline. |
| 43 |
*/ |
| 44 |
end(): void; |
| 45 |
/** |
| 46 |
* Capture the current output position so it can be rolled back with reset(). |
| 47 |
*/ |
| 48 |
mark(): Mark; |
| 49 |
/** |
| 50 |
* Roll back to a position captured with mark(). |
| 51 |
*/ |
| 52 |
reset(mark: Mark): void; |
| 53 |
/** |
| 54 |
* The number of lines written since the given mark. |
| 55 |
*/ |
| 56 |
writesSince(mark: Mark): number; |
| 57 |
toString(): string; |
| 58 |
private indent; |
| 59 |
} |
| 60 |
/** |
| 61 |
* Quote and escape a string field value as a double-quoted text format literal. |
| 62 |
* |
| 63 |
* Uses the single escaping decision in escapeCodePoint, so string fields, bytes |
| 64 |
* fields, and unknown length-delimited rendering can never drift apart. Valid |
| 65 |
* non-ASCII passes through as raw UTF-8; surrogates are never escaped. |
| 66 |
*/ |
| 67 |
export declare function quoteString(value: string): string; |
| 68 |
/** |
| 69 |
* Quote and escape a bytes field value as a double-quoted text format literal. |
| 70 |
* |
| 71 |
* Valid UTF-8 runs are emitted with escapeCodePoint (so they read identically |
| 72 |
* to a string field); any byte that is not part of a valid UTF-8 sequence is |
| 73 |
* emitted as `\xHH`, keeping the output plain ASCII that round-trips exactly. |
| 74 |
*/ |
| 75 |
export declare function quoteBytes(value: Uint8Array): string; |
| 76 |
export {}; |