Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
CompactBinaryValidation.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Memory/MemoryFwd.h"
7#include "Memory/MemoryView.h"
8#include "Misc/EnumClassFlags.h"
9#include "Serialization/CompactBinary.h"
10
11class FCbAttachment;
12class FCbPackage;
13
14///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
15
16/** Flags for validating compact binary data. */
18{
19 /** Skip validation if no other validation modes are enabled. */
20 None = 0,
21
22 /**
23 * Validate that the value can be read and stays inside the bounds of the memory view.
24 *
25 * This is the minimum level of validation required to be able to safely read a field, array,
26 * or object without the risk of crashing or reading out of bounds.
27 */
28 Default = 1 << 0,
29
30 /**
31 * Validate that object fields have unique non-empty names and array fields have no names.
32 *
33 * Name validation failures typically do not inhibit reading the input, but duplicated fields
34 * cannot be looked up by name other than the first, and converting to other data formats can
35 * fail in the presence of naming issues.
36 */
37 Names = 1 << 1,
38
39 /**
40 * Validate that fields are serialized in the canonical format.
41 *
42 * Format validation failures typically do not inhibit reading the input. Values that fail in
43 * this mode require more memory than in the canonical format, and comparisons of such values
44 * for equality are not reliable. Examples of failures include uniform arrays or objects that
45 * were not encoded uniformly, variable-length integers that could be encoded in fewer bytes,
46 * or 64-bit floats that could be encoded in 32 bits without loss of precision.
47 */
48 Format = 1 << 2,
49
50 /**
51 * Validate that there is no padding after the value before the end of the memory view.
52 *
53 * Padding validation failures have no impact on the ability to read the input, but are using
54 * more memory than necessary.
55 */
56 Padding = 1 << 3,
57
58 /**
59 * Validate that a package or attachment has the expected fields.
60 */
61 Package = 1 << 4,
62
63 /**
64 * Validate that a package or attachment matches its saved hashes.
65 */
66 PackageHash = 1 << 5,
67
68 /** Perform all validation described above. */
70};
71
73
74///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75
76/** Flags for compact binary validation errors. Multiple flags may be combined. */
78{
79 /** The input had no validation errors. */
80 None = 0,
81
82 // Mode: Default
83
84 /** The input cannot be read without reading out of bounds. */
85 OutOfBounds = 1 << 0,
86 /** The input has a field with an unrecognized or invalid type. */
87 InvalidType = 1 << 1,
88
89 // Mode: Names
90
91 /** An object had more than one field with the same name. */
92 DuplicateName = 1 << 2,
93 /** An object had a field with no name. */
94 MissingName = 1 << 3,
95 /** An array field had a name. */
96 ArrayName = 1 << 4,
97
98 // Mode: Format
99
100 /** A name or string value is not valid UTF-8. */
101 InvalidString = 1 << 5,
102 /** A size or integer value can be encoded in fewer bytes. */
103 InvalidInteger = 1 << 6,
104 /** A float64 value can be encoded as a float32 without loss of precision. */
105 InvalidFloat = 1 << 7,
106 /** An object has the same type for every field but is not uniform. */
107 NonUniformObject = 1 << 8,
108 /** An array has the same type for every field and non-empty values but is not uniform. */
109 NonUniformArray = 1 << 9,
110
111 // Mode: Padding
112
113 /** A value did not use the entire memory view given for validation. */
114 Padding = 1 << 10,
115
116 // Mode: Package
117
118 /** The package or attachment had missing fields or fields out of order. */
119 InvalidPackageFormat = 1 << 11,
120 /** The object or an attachment did not match the hash stored for it. */
121 InvalidPackageHash = 1 << 12,
122 /** The package contained more than one copy of the same attachment. */
123 DuplicateAttachments = 1 << 13,
124 /** The package contained more than one object. */
125 MultiplePackageObjects = 1 << 14,
126 /** The package contained an object with no fields. */
127 NullPackageObject = 1 << 15,
128 /** The package contained a null attachment. */
129 NullPackageAttachment = 1 << 16,
130};
131
133
134///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
135
136/**
137 * Validate the compact binary data for one field in the view as specified by the mode flags.
138 *
139 * Only one top-level field is processed from the view, and validation recurses into any array or
140 * object within that field. To validate multiple consecutive top-level fields, call the function
141 * once for each top-level field. If the given view might contain multiple top-level fields, then
142 * either exclude the Padding flag from the Mode or use MeasureCompactBinary to break up the view
143 * into its constituent fields before validating.
144 *
145 * @param View A memory view containing at least one top-level field.
146 * @param Mode A combination of the flags for the types of validation to perform.
147 * @param Type HasFieldType means that View contains the type. Otherwise, use the given type.
148 * @return None on success, otherwise the flags for the types of errors that were detected.
149 */
151
152/**
153 * Validate the compact binary data for every field in the view as specified by the mode flags.
154 *
155 * This function expects the entire view to contain fields. Any trailing region of the view which
156 * does not contain a valid field will produce an OutOfBounds or InvalidType error instead of the
157 * Padding error that would be produced by the single field validation function.
158 *
159 * @see ValidateCompactBinary
160 */
162
163/**
164 * Validate the compact binary attachment pointed to by the view as specified by the mode flags.
165 *
166 * The attachment is validated with ValidateCompactBinary by using the validation mode specified.
167 * Include ECbValidateMode::Package to validate the attachment format and hash.
168 *
169 * @see ValidateCompactBinary
170 *
171 * @param View A memory view containing a package.
172 * @param Mode A combination of the flags for the types of validation to perform.
173 * @return None on success, otherwise the flags for the types of errors that were detected.
174 */
176
177/**
178 * Validate the compact binary package pointed to by the view as specified by the mode flags.
179 *
180 * The package, and attachments, are validated with ValidateCompactBinary by using the validation
181 * mode specified. Include ECbValidateMode::Package to validate the package format and hashes.
182 *
183 * @see ValidateCompactBinary
184 *
185 * @param View A memory view containing a package.
186 * @param Mode A combination of the flags for the types of validation to perform.
187 * @return None on success, otherwise the flags for the types of errors that were detected.
188 */
190
191/**
192 * Validate the compact binary data for one value as specified by the mode flags.
193 *
194 * Validation recurses into attachments, objects, arrays, and fields within the top-level value.
195 *
196 * @return None on success, otherwise the flags for the types of errors that were detected.
197 */
203
204///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ECbFieldType
ECbValidateError ValidateCompactBinaryAttachment(FMemoryView View, ECbValidateMode Mode)
ECbValidateError ValidateCompactBinary(FMemoryView View, ECbValidateMode Mode, ECbFieldType Type=ECbFieldType::HasFieldType)
ECbValidateError ValidateCompactBinary(const FCbAttachment &Value, ECbValidateMode Mode)
ECbValidateError ValidateCompactBinaryPackage(FMemoryView View, ECbValidateMode Mode)
ECbValidateError ValidateCompactBinary(const FCbField &Value, ECbValidateMode Mode)
ECbValidateError ValidateCompactBinaryRange(FMemoryView View, ECbValidateMode Mode)
ECbValidateError ValidateCompactBinary(const FCbPackage &Value, ECbValidateMode Mode)
ECbValidateError ValidateCompactBinary(const FCbObject &Value, ECbValidateMode Mode)
ECbValidateError ValidateCompactBinary(const FCbArray &Value, ECbValidateMode Mode)
#define ENUM_CLASS_FLAGS(Enum)
ECbValidateError
Definition Enums.h:34249
ECbValidateMode
Definition Enums.h:34237