Skip to content

Commit 75ecd23

Browse files
committed
2 parents 0003dad + 141e84e commit 75ecd23

File tree

5 files changed

+308
-0
lines changed

5 files changed

+308
-0
lines changed

src/main/java/io/kaitai/struct/KaitaiStream.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,4 +575,30 @@ public ValidationNotEqualError(Object expected, Object actual, KaitaiStream io,
575575
protected Object expected;
576576
protected Object actual;
577577
}
578+
579+
public static class ValidationLessThanError extends ValidationFailedError {
580+
public ValidationLessThanError(long min, long actual, KaitaiStream io, String srcPath) {
581+
super("not in range, min " + min + ", but got " + actual, io, srcPath);
582+
}
583+
584+
protected long min;
585+
protected long actual;
586+
}
587+
588+
public static class ValidationGreaterThanError extends ValidationFailedError {
589+
public ValidationGreaterThanError(long max, long actual, KaitaiStream io, String srcPath) {
590+
super("not in range, max " + max + ", but got " + actual, io, srcPath);
591+
}
592+
593+
protected long max;
594+
protected long actual;
595+
}
596+
597+
public static class ValidationNotAnyOfError extends ValidationFailedError {
598+
public ValidationNotAnyOfError(Object actual, KaitaiStream io, String srcPath) {
599+
super("not any of the list, got " + actual, io, srcPath);
600+
}
601+
602+
protected Object actual;
603+
}
578604
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* Copyright 2015-2020 Kaitai Project: MIT license
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
package io.kaitai.struct.annotations;
24+
25+
import java.lang.annotation.Documented;
26+
import java.lang.annotation.ElementType;
27+
import java.lang.annotation.Retention;
28+
import java.lang.annotation.RetentionPolicy;
29+
import java.lang.annotation.Target;
30+
31+
/**
32+
* Annotation, that applied to Kaitai-generated classes. Visualizers can use that
33+
* annotation to find classes, that contains generated stuff, that should be showed
34+
* in visualization.
35+
*
36+
* @since 0.9
37+
*/
38+
@Documented
39+
@Retention(RetentionPolicy.RUNTIME)
40+
@Target(ElementType.TYPE)
41+
public @interface Generated {
42+
/**
43+
* Original identifier ({@code id} key) from {@code ksy} file.
44+
*
45+
* @return Identifier, that can differ from class name, if it clash with
46+
* Java reserved words. Can not be empty
47+
*/
48+
String id();
49+
/**
50+
* Version of compiler, that generated this class.
51+
*
52+
* @return Version string in <a href="https://semver.org/">semver</a> format
53+
*/
54+
String version();
55+
/**
56+
* Class compiled with support of position tracking. That means, that every class
57+
* has following public fields (in that version of generator):
58+
* <table>
59+
* <tr><th>Type</th><th>Field</th><th>Description</th></tr>
60+
* <tr><td>{@code Map<String, Integer>}</td><td>{@code _attrStart}</td>
61+
* <td>Start offset in the root stream, where {@link SeqItem an attribute} or
62+
* {@link Instance an instance} with specified name begins.
63+
* Used only for attributes/instances, that is not repeated</td>
64+
* </tr>
65+
* <tr><td>{@code Map<String, Integer>}</td><td>{@code _attrEnd}</td>
66+
* <td>Start offset in the root stream, where {@link SeqItem an attribute} or
67+
* {@link Instance an instance} with specified name ends (exclusive).
68+
* Used only for attributes/instances, that is not repeated</td>
69+
* </tr>
70+
* <tr><td>{@code Map<String, ? extends List<Integer>>}</td><td>{@code _arrStart}</td>
71+
* <td>List with start offset in the root stream, where each array element of
72+
* repeated {@link SeqItem attribute} or {@link Instance instance} with
73+
* specified name begins. Used only for attributes/instances, that is repeated</td>
74+
* </tr>
75+
* <tr><td>{@code Map<String, ? extends List<Integer>>}</td><td>{@code _arrEnd}</td>
76+
* <td>List with end offset (exclusive) in the root stream, where each array
77+
* element of repeated {@link SeqItem attribute} or {@link Instance instance}
78+
* with specified name ends. Used only for attributes/instances, that is repeated</td>
79+
* </tr>
80+
* </table>
81+
*
82+
* @return {@code true}, if position tracking is enabled and {@code false} otherwise
83+
*/
84+
boolean posInfo();
85+
/**
86+
* Determines, if instantiation of user classes (related to user-types, defined
87+
* in {@code ksy} file) automatically read its content from the stream, or that must
88+
* be performed manually by calling generated {@code _read()}, {@code _readBE()}
89+
* or {@code _readLE()} method.
90+
*
91+
* @return {@code true}, if generated {@code _read()} method invoked automatically
92+
* by class constructors and {@code false}, if it must be called explicitly
93+
*/
94+
boolean autoRead();
95+
/**
96+
* Documentation string attached to the type definition, specified in {@code doc}
97+
* KSY element.
98+
*
99+
* @return Documentation string for a type. If documentation is missed, returns empty string
100+
*/
101+
String doc();
102+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Copyright 2015-2020 Kaitai Project: MIT license
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
package io.kaitai.struct.annotations;
24+
25+
import java.lang.annotation.Documented;
26+
import java.lang.annotation.ElementType;
27+
import java.lang.annotation.Retention;
28+
import java.lang.annotation.RetentionPolicy;
29+
import java.lang.annotation.Target;
30+
31+
/**
32+
* Annotation, that applied to fields, getters or setters that represents instance
33+
* field from {@code instances} KSY element.
34+
*
35+
* @since 0.9
36+
*/
37+
@Documented
38+
@Retention(RetentionPolicy.RUNTIME)
39+
@Target({ElementType.FIELD, ElementType.METHOD})
40+
public @interface Instance {
41+
/**
42+
* Original identifier ({@code id} key) from {@code ksy} file.
43+
*
44+
* @return Identifier, that can differ from instance name, if it clash with
45+
* Java reserved words. Can not be empty
46+
*/
47+
String id();
48+
/**
49+
* Documentation string attached to the instance definition, specified in {@code doc}
50+
* KSY element.
51+
*
52+
* @return Documentation string for an instance. If documentation is missed,
53+
* returns empty string
54+
*/
55+
String doc();
56+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright 2015-2020 Kaitai Project: MIT license
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
package io.kaitai.struct.annotations;
24+
25+
import java.lang.annotation.Documented;
26+
import java.lang.annotation.ElementType;
27+
import java.lang.annotation.Retention;
28+
import java.lang.annotation.RetentionPolicy;
29+
import java.lang.annotation.Target;
30+
31+
/**
32+
* Annotation, that applied to fields, getters or setters that represents parameter
33+
* from {@code params} KSY element.
34+
*
35+
* @since 0.9
36+
*/
37+
@Documented
38+
@Retention(RetentionPolicy.RUNTIME)
39+
@Target({ElementType.FIELD, ElementType.METHOD})
40+
public @interface Parameter {
41+
/**
42+
* Original identifier ({@code id} key) from {@code ksy} file.
43+
*
44+
* @return Identifier, that can differ from parameter name, if it clash with
45+
* Java reserved words. Can not be empty
46+
*/
47+
String id();
48+
/**
49+
* Index of a parameter in sequence of parameters in the type.
50+
*
51+
* @return 0-based index of a parameter in {@code params} KSY element
52+
*/
53+
int index();
54+
/**
55+
* Documentation string attached to the parameter, specified in {@code doc}
56+
* KSY element.
57+
*
58+
* @return Documentation string for parameter. If documentation is missed,
59+
* returns empty string
60+
*/
61+
String doc();
62+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright 2015-2020 Kaitai Project: MIT license
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
package io.kaitai.struct.annotations;
24+
25+
import java.lang.annotation.Documented;
26+
import java.lang.annotation.ElementType;
27+
import java.lang.annotation.Retention;
28+
import java.lang.annotation.RetentionPolicy;
29+
import java.lang.annotation.Target;
30+
31+
/**
32+
* Annotation, that applied to fields, getters or setters that represents an attribute
33+
* from {@code seq} KSY element.
34+
*
35+
* @since 0.9
36+
*/
37+
@Documented
38+
@Retention(RetentionPolicy.RUNTIME)
39+
@Target({ElementType.FIELD, ElementType.METHOD})
40+
public @interface SeqItem {
41+
/**
42+
* Original identifier ({@code id} key) from {@code ksy} file.
43+
*
44+
* @return Identifier, that can differ from field name, if it clash with
45+
* Java reserved words. Empty string, if attribute was unnamed
46+
*/
47+
String id();
48+
/**
49+
* Index of an attribute in sequence of attributes in the type.
50+
*
51+
* @return 0-based index of an attribute in {@code seq} KSY element
52+
*/
53+
int index();
54+
/**
55+
* Documentation string attached to the attribute, specified in {@code doc}
56+
* KSY element.
57+
*
58+
* @return Documentation string for and attribute. If documentation is missed,
59+
* returns empty string
60+
*/
61+
String doc();
62+
}

0 commit comments

Comments
 (0)