| 249 | } |
| 250 | |
| 251 | func (x *xerialWriter) Flush() error { |
| 252 | if len(x.input) == 0 { |
| 253 | return nil |
| 254 | } |
| 255 | |
| 256 | var b []byte |
| 257 | if x.encode == nil { |
| 258 | b = x.input |
| 259 | } else { |
| 260 | x.output = x.encode(x.output[:cap(x.output)], x.input) |
| 261 | b = x.output |
| 262 | } |
| 263 | |
| 264 | x.input = x.input[:0] |
| 265 | x.output = x.output[:0] |
| 266 | |
| 267 | if x.framed && x.nbytes == 0 { |
| 268 | writeXerialHeader(x.header[:]) |
| 269 | _, err := x.write(x.header[:]) |
| 270 | if err != nil { |
| 271 | return err |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | if x.framed { |
| 276 | writeXerialFrame(x.header[:4], len(b)) |
| 277 | _, err := x.write(x.header[:4]) |
| 278 | if err != nil { |
| 279 | return err |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | _, err := x.write(b) |
| 284 | return err |
| 285 | } |
| 286 | |
| 287 | func (x *xerialWriter) write(b []byte) (int, error) { |
| 288 | n, err := x.writer.Write(b) |