Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/fmt/java/defs.h

raw
1 /*
2 * Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2025 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 28 авг. 2019 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_FMT_JAVA_HEADERS_H_
23 #define LSP_PLUG_IN_FMT_JAVA_HEADERS_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/common/types.h>
27 #include <lsp-plug.in/fmt/java/const.h>
28
29 #define JAVA_STREAM_MAGIC 0xACED
30 #define JAVA_BASE_WIRE_HANDLE 0x7e0000
31 #define JAVA_MAX_BLOCK_SIZE 1024
32
33 namespace lsp
34 {
35 namespace java
36 {
37 enum obj_stream_tag_t
38 {
39 TC_NULL = 0x70, ///< Null object reference.
40 TC_REFERENCE = 0x71, ///< Reference to an object already written into the stream.
41 TC_CLASSDESC = 0x72, ///< new Class Descriptor.
42 TC_OBJECT = 0x73, ///< new Object.
43 TC_STRING = 0x74, ///< new String.
44 TC_ARRAY = 0x75, ///< new Array.
45 TC_CLASS = 0x76, ///< Reference to Class.
46 TC_BLOCKDATA = 0x77, ///< Block of optional data. Byte following tag indicates number of bytes in this block data.
47 TC_ENDBLOCKDATA = 0x78, ///< End of optional block data blocks for an object.
48 TC_RESET = 0x79, ///< Reset stream context. All handles written into stream are reset.
49 TC_BLOCKDATALONG = 0x7A, ///< long Block data. The long following the tag indicates the number of bytes in this block data.
50 TC_EXCEPTION = 0x7B, ///< Exception during write.
51 TC_LONGSTRING = 0x7C, ///< Long string.
52 TC_PROXYCLASSDESC = 0x7D, ///< new Proxy Class Descriptor.
53 TC_ENUM = 0x7E, ///< new Enum constant, since java 1.5
54
55 TC_BASE = TC_NULL, ///< First tag value
56 TC_MAX = TC_ENUM ///< Last tag value.
57 };
58
59 enum obj_stream_const_t
60 {
61 /**
62 * Bit mask for ObjectStreamClass flag. Indicates a Serializable class
63 * defines its own writeObject method.
64 */
65 SC_WRITE_METHOD = 0x01,
66
67 /**
68 * Bit mask for ObjectStreamClass flag. Indicates class is Serializable.
69 */
70 SC_SERIALIZABLE = 0x02,
71
72 /**
73 * Bit mask for ObjectStreamClass flag. Indicates class is Externalizable.
74 */
75 SC_EXTERNALIZABLE = 0x04,
76
77 /**
78 * Bit mask for ObjectStreamClass flag. Indicates Externalizable data
79 * written in Block Data mode.
80 * Added for PROTOCOL_VERSION_2.
81 */
82 SC_BLOCK_DATA = 0x08,
83
84 /**
85 * Bit mask for ObjectStreamClass flag. Indicates class is an enum type.
86 * @since 1.5
87 */
88 SC_ENUM = 0x10
89 };
90
91 enum prim_type_t
92 {
93 PTC_BYTE = 'B', ///< byte
94 PTC_CHAR = 'C', ///< char
95 PTC_DOUBLE = 'D', ///< double
96 PTC_FLOAT = 'F', ///< float
97 PTC_INTEGER = 'I', ///< integer
98 PTC_LONG = 'J', ///< long
99 PTC_SHORT = 'S', ///< short
100 PTC_BOOL = 'Z', ///< boolean
101 PTC_ARRAY = '[', ///< array
102 PTC_OBJECT = 'L' ///< object
103 };
104
105
106 class Object;
107
108 #pragma pack(push, 1)
109 typedef struct obj_stream_hdr_t
110 {
111 uint16_t magic;
112 uint16_t version;
113 } obj_stream_hdr_t;
114
115 typedef union prim_ptr_t
116 {
117 int8_t *p_byte __lsp_packed;
118 uint8_t *p_ubyte __lsp_packed;
119 int16_t *p_short __lsp_packed;
120 uint16_t *p_ushort __lsp_packed;
121 int32_t *p_int __lsp_packed;
122 uint32_t *p_uint __lsp_packed;
123 int64_t *p_long __lsp_packed;
124 uint64_t *p_ulong __lsp_packed;
125 lsp_utf16_t *p_char __lsp_packed;
126 double_t *p_double __lsp_packed;
127 float_t *p_float __lsp_packed;
128 bool_t *p_bool __lsp_packed;
129 Object **p_object __lsp_packed;
130 void *p_void __lsp_packed;
131 } prim_ptr_t;
132 #pragma pack(pop)
133
134 struct obj_ptr_t
135 {
136 private:
137 Object **obj;
138
139 public:
140 inline obj_ptr_t(Object **p) { obj = p; }
141 inline obj_ptr_t & operator = (Object **p) { obj = p; return *this; }
142 inline operator Object **() { return obj; }
143
144 template <typename type_t>
145 inline obj_ptr_t(type_t **p)
146 {
147 union { Object **o; type_t **t; } x;
148 x.t = p;
149 obj = x.o;
150 }
151
152 template <typename type_t>
153 inline obj_ptr_t & operator = (type_t **p)
154 {
155 union { Object **o; type_t **t; } x;
156 x.t = p;
157 obj = x.o;
158 return *this;
159 }
160
161 template <typename type_t>
162 inline operator type_t **()
163 {
164 union { Object **o; type_t **t; } x;
165 x.o = obj;
166 return x.t;
167 }
168 };
169
170 /**
171 * Decode primitive type
172 * @param tcode type code
173 * @return decoded result
174 */
175 ftype_t decode_primitive_type(size_t tcode);
176
177 /**
178 * Get primitive type name
179 * @param tcode primitive type code
180 * @return primitive type name or NULL if type is non-primitive
181 */
182 const char *primitive_type_name(ftype_t tcode);
183
184 } /* namespace java */
185 } /* namespace lsp */
186
187 #endif /* LSP_PLUG_IN_FMT_JAVA_HEADERS_H_ */