summaryrefslogtreecommitdiff
path: root/docs/data/core/buffer_view.json
blob: bf07694c6f5430d7b2ad0fcd0a08375da0164008 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{
	"format": 1,
	"id": "saw-buffer_view",
	"kind": "class",
	"name": "buffer_view",
	"namespace": "saw",
	"module": "core",
	"header": "modules/core/c++/buffer.hpp",
	"brief_description": "A viewer class for buffers.",
	"detailed_description": [
		[
			"Carries its own cursors over somebody else's",
			{"name": "buffer", "id": "saw-buffer"},
			"so a decoder can walk forward, discover the input is incomplete, and leave the underlying buffer untouched. Only once the operation succeeded does the caller advance the real buffer by the view's offset."
		],
		[
			"That is the whole speculative parsing mechanism in this codebase. The codecs decode into a view and commit afterwards."
		],
		[
			"Working on the referenced buffer invalidates the view."
		]
	],
	"bases": [
		[{"name": "buffer", "id": "saw-buffer"}]
	],
	"functions": {
		"saw-buffer_view-ctor-1": {
			"id": "saw-buffer_view-ctor-1",
			"name": "buffer_view",
			"type": [],
			"parameters": [
				{"name": "buffer", "type": [{"name": "buffer", "id": "saw-buffer"}, "&"]}
			]
		},
		"saw-buffer_view-ctor-2": {
			"id": "saw-buffer_view-ctor-2",
			"name": "buffer_view",
			"type": [],
			"brief_description": "With an upper bound on what may be read and written through it.",
			"parameters": [
				{"name": "buffer", "type": [{"name": "buffer", "id": "saw-buffer"}, "&"]},
				{"name": "limit_read_len", "type": ["uint64_t"]},
				{"name": "limit_write_len", "type": ["uint64_t"]}
			]
		},
		"saw-buffer_view-read_offset": {
			"id": "saw-buffer_view-read_offset",
			"name": "read_offset",
			"type": ["size_t"],
			"const": true,
			"brief_description": "How far the view has read ahead of the underlying buffer.",
			"detailed_description": [
				["This is what gets handed to read_advance on the real buffer once the read is known to have succeeded."]
			]
		},
		"saw-buffer_view-write_offset": {
			"id": "saw-buffer_view-write_offset",
			"name": "write_offset",
			"type": ["size_t"],
			"const": true,
			"brief_description": "How far the view has written ahead of the underlying buffer."
		}
	},
	"examples": [
		{
			"title": "Decoding without consuming on failure",
			"description": [
				["The shape every codec uses. If the decode fails, the buffer is left exactly as it was and the caller can try again once more data arrived."]
			],
			"language": "cpp",
			"code": "buffer_view buff_v{from_decode.get_buffer()};\n\nauto eov = impl::json_decode<Schema, ToEncoding>::decode(buff_v, to_decode, cfg_);\nif(eov.is_error()){\n\treturn std::move(eov.get_error());\n}\n\n/// Only now is the input really consumed.\nfrom_decode.get_buffer().read_advance(buff_v.read_offset());\n"
		}
	]
}