Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitai-bot committed Aug 24, 2024
1 parent 883896c commit ca253f1
Show file tree
Hide file tree
Showing 22 changed files with 583 additions and 6 deletions.
13 changes: 13 additions & 0 deletions compiled/construct/valid_fail_in_enum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from construct import *
from construct.lib import *
import enum

class valid_fail_in_enum__animal(enum.IntEnum):
dog = 4
chicken = 12

valid_fail_in_enum = Struct(
'foo' / Enum(Int32ul, valid_fail_in_enum__animal),
)

_schema = valid_fail_in_enum
2 changes: 1 addition & 1 deletion compiled/cpp_stl_11/enum_int_range_s.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

#include "enum_int_range_s.h"
const std::set<std::underlying_type<enum_int_range_s_t::constants_t>::type> enum_int_range_s_t::_values_constants_t{-2147483648, 0, 2147483647};
const std::set<std::underlying_type<enum_int_range_s_t::constants_t>::type> enum_int_range_s_t::_values_constants_t{-2147483647 - 1, 0, 2147483647};

enum_int_range_s_t::enum_int_range_s_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, enum_int_range_s_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
Expand Down
2 changes: 1 addition & 1 deletion compiled/cpp_stl_11/enum_int_range_u.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

#include "enum_int_range_u.h"
const std::set<std::underlying_type<enum_int_range_u_t::constants_t>::type> enum_int_range_u_t::_values_constants_t{0, 4294967295};
const std::set<std::underlying_type<enum_int_range_u_t::constants_t>::type> enum_int_range_u_t::_values_constants_t{0, 4294967295UL};

enum_int_range_u_t::enum_int_range_u_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, enum_int_range_u_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
Expand Down
2 changes: 1 addition & 1 deletion compiled/cpp_stl_11/enum_long_range_s.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

#include "enum_long_range_s.h"
const std::set<std::underlying_type<enum_long_range_s_t::constants_t>::type> enum_long_range_s_t::_values_constants_t{-9223372036854775808, -2147483649, -2147483648, 0, 2147483647, 2147483648, 9223372036854775807};
const std::set<std::underlying_type<enum_long_range_s_t::constants_t>::type> enum_long_range_s_t::_values_constants_t{-9223372036854775807LL - 1, -2147483649LL, -2147483647 - 1, 0, 2147483647, 2147483648UL, 9223372036854775807LL};

enum_long_range_s_t::enum_long_range_s_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, enum_long_range_s_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
Expand Down
2 changes: 1 addition & 1 deletion compiled/cpp_stl_11/enum_long_range_u.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

#include "enum_long_range_u.h"
const std::set<std::underlying_type<enum_long_range_u_t::constants_t>::type> enum_long_range_u_t::_values_constants_t{0, 4294967295, 4294967296, 9223372036854775807};
const std::set<std::underlying_type<enum_long_range_u_t::constants_t>::type> enum_long_range_u_t::_values_constants_t{0, 4294967295UL, 4294967296LL, 9223372036854775807LL};

enum_long_range_u_t::enum_long_range_u_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, enum_long_range_u_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
Expand Down
25 changes: 25 additions & 0 deletions compiled/cpp_stl_11/valid_fail_in_enum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

#include "valid_fail_in_enum.h"
#include "kaitai/exceptions.h"
const std::set<std::underlying_type<valid_fail_in_enum_t::animal_t>::type> valid_fail_in_enum_t::_values_animal_t{4, 12};

valid_fail_in_enum_t::valid_fail_in_enum_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, valid_fail_in_enum_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root ? p__root : this;
_read();
}

void valid_fail_in_enum_t::_read() {
m_foo = static_cast<valid_fail_in_enum_t::animal_t>(m__io->read_u4le());
if (valid_fail_in_enum_t::_values_animal_t.find(m_foo) == valid_fail_in_enum_t::_values_animal_t.end()) {
throw kaitai::validation_not_in_enum_error<valid_fail_in_enum_t::animal_t>(m_foo, m__io, std::string("/seq/0"));
}
}

valid_fail_in_enum_t::~valid_fail_in_enum_t() {
_clean_up();
}

void valid_fail_in_enum_t::_clean_up() {
}
45 changes: 45 additions & 0 deletions compiled/cpp_stl_11/valid_fail_in_enum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

class valid_fail_in_enum_t;

#include "kaitai/kaitaistruct.h"
#include <stdint.h>
#include <memory>
#include <set>
#include <type_traits>

#if KAITAI_STRUCT_VERSION < 11000L
#error "Incompatible Kaitai Struct C++/STL API: version 0.11 or later is required"
#endif

class valid_fail_in_enum_t : public kaitai::kstruct {

public:

enum animal_t {
ANIMAL_DOG = 4,
ANIMAL_CHICKEN = 12
};
static const std::set<std::underlying_type<animal_t>::type> _values_animal_t;

valid_fail_in_enum_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, valid_fail_in_enum_t* p__root = nullptr);

private:
void _read();
void _clean_up();

public:
~valid_fail_in_enum_t();

private:
animal_t m_foo;
valid_fail_in_enum_t* m__root;
kaitai::kstruct* m__parent;

public:
animal_t foo() const { return m_foo; }
valid_fail_in_enum_t* _root() const { return m__root; }
kaitai::kstruct* _parent() const { return m__parent; }
};
41 changes: 41 additions & 0 deletions compiled/csharp/ValidFailInEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

using System;

namespace Kaitai
{
public partial class ValidFailInEnum : KaitaiStruct
{
public static ValidFailInEnum FromFile(string fileName)
{
return new ValidFailInEnum(new KaitaiStream(fileName));
}


public enum Animal
{
Dog = 4,
Chicken = 12,
}
public ValidFailInEnum(KaitaiStream p__io, KaitaiStruct p__parent = null, ValidFailInEnum p__root = null) : base(p__io)
{
m_parent = p__parent;
m_root = p__root ?? this;
_read();
}
private void _read()
{
_foo = ((Animal) m_io.ReadU4le());
if (!Enum.IsDefined(typeof(Animal), _foo))
{
throw new ValidationNotInEnumError(_foo, m_io, "/seq/0");
}
}
private Animal _foo;
private ValidFailInEnum m_root;
private KaitaiStruct m_parent;
public Animal Foo { get { return _foo; } }
public ValidFailInEnum M_Root { get { return m_root; } }
public KaitaiStruct M_Parent { get { return m_parent; } }
}
}
47 changes: 47 additions & 0 deletions compiled/go/src/test_formats/valid_fail_in_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions compiled/graphviz/valid_fail_in_enum.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
digraph {
rankdir=LR;
node [shape=plaintext];
subgraph cluster__valid_fail_in_enum {
label="ValidFailInEnum";
graph[style=dotted];

valid_fail_in_enum__seq [label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
<TR><TD BGCOLOR="#E0FFE0">pos</TD><TD BGCOLOR="#E0FFE0">size</TD><TD BGCOLOR="#E0FFE0">type</TD><TD BGCOLOR="#E0FFE0">id</TD></TR>
<TR><TD PORT="foo_pos">0</TD><TD PORT="foo_size">4</TD><TD>u4le→Animal</TD><TD PORT="foo_type">foo</TD></TR>
<TR><TD COLSPAN="4" PORT="foo__valid">must be defined in the enum</TD></TR>
</TABLE>>];
}
}
55 changes: 55 additions & 0 deletions compiled/html/valid_fail_in_enum.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

<title>ValidFailInEnum format specification</title>
</head>
<body>
<div class="container">
<h1>ValidFailInEnum format specification</h1>


<a name='type-valid_fail_in_enum'></a>
<h1>Type: ValidFailInEnum</h1>

<table class="table">
<tr><th>Offset</th><th>Size</th><th>ID</th><th>Type</th><th>Note</th></tr>
<tr>
<td>0</td>
<td>...</td>
<td>foo</td>
<td>u4le→Animal</td>
<td></td>
</tr>
</table>
<a name='enum-valid_fail_in_enum-animal'></a>
<h2>Enum: animal</h2>

<table class="table">
<tr>
<th>ID</th><th>Name</th><th>Note</th>
</tr>
<tr>
<td>4</td><td>dog</td><td></td></tr>
</tr>
<tr>
<td>12</td><td>chicken</td><td></td></tr>
</tr>
</table>

</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
</body>
</html>

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

package io.kaitai.struct.testformats;

import io.kaitai.struct.ByteBufferKaitaiStream;
import io.kaitai.struct.KaitaiStruct;
import io.kaitai.struct.KaitaiStream;
import java.io.IOException;
import java.util.Map;
import java.util.HashMap;

public class ValidFailInEnum extends KaitaiStruct {
public static ValidFailInEnum fromFile(String fileName) throws IOException {
return new ValidFailInEnum(new ByteBufferKaitaiStream(fileName));
}

public enum Animal {
DOG(4),
CHICKEN(12);

private final long id;
Animal(long id) { this.id = id; }
public long id() { return id; }
private static final Map<Long, Animal> byId = new HashMap<Long, Animal>(2);
static {
for (Animal e : Animal.values())
byId.put(e.id(), e);
}
public static Animal byId(long id) { return byId.get(id); }
}

public ValidFailInEnum(KaitaiStream _io) {
this(_io, null, null);
}

public ValidFailInEnum(KaitaiStream _io, KaitaiStruct _parent) {
this(_io, _parent, null);
}

public ValidFailInEnum(KaitaiStream _io, KaitaiStruct _parent, ValidFailInEnum _root) {
super(_io);
this._parent = _parent;
this._root = _root == null ? this : _root;
_read();
}
private void _read() {
this.foo = Animal.byId(this._io.readU4le());
if (this.foo == null) {
throw new KaitaiStream.ValidationNotInEnumError(this.foo, this._io, "/seq/0");
}
}
private Animal foo;
private ValidFailInEnum _root;
private KaitaiStruct _parent;
public Animal foo() { return foo; }
public ValidFailInEnum _root() { return _root; }
public KaitaiStruct _parent() { return _parent; }
}
38 changes: 38 additions & 0 deletions compiled/javascript/ValidFailInEnum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['exports', 'kaitai-struct/KaitaiStream'], factory);
} else if (typeof exports === 'object' && exports !== null && typeof exports.nodeType !== 'number') {
factory(exports, require('kaitai-struct/KaitaiStream'));
} else {
factory(root.ValidFailInEnum || (root.ValidFailInEnum = {}), root.KaitaiStream);
}
})(typeof self !== 'undefined' ? self : this, function (ValidFailInEnum_, KaitaiStream) {
var ValidFailInEnum = (function() {
ValidFailInEnum.Animal = Object.freeze({
DOG: 4,
CHICKEN: 12,

4: "DOG",
12: "CHICKEN",
});

function ValidFailInEnum(_io, _parent, _root) {
this._io = _io;
this._parent = _parent;
this._root = _root || this;

this._read();
}
ValidFailInEnum.prototype._read = function() {
this.foo = this._io.readU4le();
if (!Object.prototype.hasOwnProperty.call(ValidFailInEnum.Animal, this.foo)) {
throw new KaitaiStream.ValidationNotInEnumError(this.foo, this._io, "/seq/0");
}
}

return ValidFailInEnum;
})();
ValidFailInEnum_.ValidFailInEnum = ValidFailInEnum;
});
Loading

0 comments on commit ca253f1

Please sign in to comment.