Scott Baker | bdb962b | 2020-04-03 10:53:36 -0700 | [diff] [blame] | 1 | package yaml |
| 2 | |
| 3 | // Set the writer error and return false. |
| 4 | func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { |
| 5 | emitter.error = yaml_WRITER_ERROR |
| 6 | emitter.problem = problem |
| 7 | return false |
| 8 | } |
| 9 | |
| 10 | // Flush the output buffer. |
| 11 | func yaml_emitter_flush(emitter *yaml_emitter_t) bool { |
| 12 | if emitter.write_handler == nil { |
| 13 | panic("write handler not set") |
| 14 | } |
| 15 | |
| 16 | // Check if the buffer is empty. |
| 17 | if emitter.buffer_pos == 0 { |
| 18 | return true |
| 19 | } |
| 20 | |
| 21 | if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil { |
| 22 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) |
| 23 | } |
| 24 | emitter.buffer_pos = 0 |
| 25 | return true |
| 26 | } |