Line data Source code
1 : /*
2 : * Package : Cbor
3 : * Author : S. Hamblett <steve.hamblett@linux.com>
4 : * Date : 12/12/2016
5 : * Copyright : S.Hamblett
6 : */
7 :
8 : part of cbor;
9 :
10 : /// A base class for encoder output.
11 : /// Derived classes must implement these methods as a minimum
12 : /// to provide full CBOR encoding.
13 : abstract class Output {
14 : /// The encoded output buffer
15 : typed.Uint8Buffer _buffer;
16 :
17 : /// The paused buffer
18 : typed.Uint8Buffer _pauseBuffer;
19 :
20 : /// Pause indicator
21 : bool _paused = false;
22 :
23 : /// Position of the last mark operation
24 : int _markPos = 0;
25 :
26 : /// Get the current output buffer
27 : typed.Uint8Buffer getData() {
28 4 : final typed.Uint8Buffer ret = new typed.Uint8Buffer();
29 8 : ret.addAll(_buffer);
30 : return ret;
31 : }
32 :
33 : /// Clear the buffer
34 : void clear();
35 :
36 : /// Current buffer size
37 : int size();
38 :
39 : /// Write asingle byte
40 : void putByte(int value);
41 :
42 : /// Write multiple bytes
43 : void putBytes(typed.Uint8Buffer data);
44 :
45 : /// Mark the current buffers position. Used for rollback
46 : /// in conjunction with the resetToMark method. Only one mark
47 : /// can be in force at a time, they cannot be nested. Marking
48 : /// only applies to the encoded output buffer.
49 : void mark();
50 :
51 : /// Resets the buffer back to its last mark position, used to protect
52 : /// complex encodes(arrays, maps) that may not work.
53 : void resetToMark();
54 :
55 : /// Pauses encoding, copies the encoded output buffer to the pause buffer,
56 : /// and clears the output buffer. Further encoding carries on as normal
57 : /// in the output buffer. Used to encode CBOR items as standalone entities
58 : /// for later inclusion in the main encoding stream, e.g map values. Has
59 : /// no effect if already paused.
60 : void pause();
61 :
62 : /// Restart after pause, copies the pause buffer back into the output buffer,
63 : /// if append is true the current output buffer contents are appended to the
64 : /// pause buffer.
65 : void restart([bool append = false]);
66 : }
|