| 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_OBJECTSTREAM_H_ |
| 23 |
#define LSP_PLUG_IN_FMT_JAVA_OBJECTSTREAM_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/runtime/LSPString.h> |
| 27 |
#include <lsp-plug.in/common/types.h> |
| 28 |
#include <lsp-plug.in/common/status.h> |
| 29 |
#include <lsp-plug.in/io/Path.h> |
| 30 |
#include <lsp-plug.in/io/IInStream.h> |
| 31 |
|
| 32 |
#include <lsp-plug.in/fmt/java/const.h> |
| 33 |
#include <lsp-plug.in/fmt/java/Object.h> |
| 34 |
#include <lsp-plug.in/fmt/java/String.h> |
| 35 |
#include <lsp-plug.in/fmt/java/RawArray.h> |
| 36 |
#include <lsp-plug.in/fmt/java/Enum.h> |
| 37 |
#include <lsp-plug.in/fmt/java/Handles.h> |
| 38 |
#include <lsp-plug.in/fmt/java/ObjectStreamField.h> |
| 39 |
#include <lsp-plug.in/fmt/java/ObjectStreamClass.h> |
| 40 |
|
| 41 |
namespace lsp |
| 42 |
{ |
| 43 |
namespace java |
| 44 |
{ |
| 45 |
class ObjectStream |
| 46 |
{ |
| 47 |
protected: |
| 48 |
typedef struct block_t |
| 49 |
{ |
| 50 |
uint8_t *data; |
| 51 |
size_t size; |
| 52 |
size_t offset; |
| 53 |
size_t unread; |
| 54 |
bool enabled; |
| 55 |
} block_t; |
| 56 |
|
| 57 |
protected: |
| 58 |
io::IInStream *pIS; |
| 59 |
size_t nFlags; |
| 60 |
status_t nToken; |
| 61 |
stream_token_t enToken; |
| 62 |
size_t nDepth; |
| 63 |
ssize_t nVersion; |
| 64 |
Handles *pHandles; |
| 65 |
block_t sBlock; |
| 66 |
String *vTypeStrings[JFT_TOTAL]; |
| 67 |
|
| 68 |
private: |
| 69 |
status_t do_close(); |
| 70 |
status_t set_block_mode(bool enabled, bool *old = NULL); |
| 71 |
status_t intern_type_string(String **dst, ftype_t type, char ptype); |
| 72 |
|
| 73 |
protected: |
| 74 |
status_t initial_read(io::IInStream *is); |
| 75 |
status_t get_token(); |
| 76 |
status_t lookup_token(); |
| 77 |
inline void clear_token(); |
| 78 |
|
| 79 |
status_t fill_block(); |
| 80 |
status_t read_fully(void *dst, size_t count); |
| 81 |
|
| 82 |
status_t skip_block_data(); |
| 83 |
status_t skip_custom_data(); |
| 84 |
status_t read_custom_data(void **dst, size_t *size); |
| 85 |
status_t parse_array(RawArray **dst); |
| 86 |
status_t parse_enum(Enum **dst); |
| 87 |
status_t parse_ordinary_object(Object **dst); |
| 88 |
status_t parse_reset(); |
| 89 |
status_t parse_null(Object **dst); |
| 90 |
status_t parse_class_field(ObjectStreamField **dst); |
| 91 |
status_t parse_class_descriptor(ObjectStreamClass **dst); |
| 92 |
status_t parse_proxy_class_descriptor(ObjectStreamClass **dst); |
| 93 |
status_t parse_utf(LSPString *dst, size_t len); |
| 94 |
status_t parse_reference(Object **dst, const char *type = NULL); |
| 95 |
status_t parse_string(String **dst); |
| 96 |
status_t parse_object(Object **dst); |
| 97 |
status_t parse_serial_data(Object *dst, ObjectStreamClass *desc); |
| 98 |
status_t parse_external_data(Object *dst, ObjectStreamClass *desc); |
| 99 |
|
| 100 |
Object *build_object(ObjectStreamClass *desc); |
| 101 |
|
| 102 |
inline status_t start_object(bool &mode); |
| 103 |
inline status_t end_object(bool &mode, status_t res); |
| 104 |
|
| 105 |
public: |
| 106 |
explicit ObjectStream(Handles *handles); |
| 107 |
virtual ~ObjectStream(); |
| 108 |
|
| 109 |
public: |
| 110 |
/** |
| 111 |
* Open stream reader |
| 112 |
* @param file location of the file in UTF-8 encoding |
| 113 |
* @return status of operation |
| 114 |
*/ |
| 115 |
status_t open(const char *file); |
| 116 |
|
| 117 |
/** |
| 118 |
* Open stream reader |
| 119 |
* @param file location of the file |
| 120 |
* @return status of operation |
| 121 |
*/ |
| 122 |
status_t open(const LSPString *file); |
| 123 |
|
| 124 |
/** |
| 125 |
* Open stream reader |
| 126 |
* @param file location of the file |
| 127 |
* @return status of operation |
| 128 |
*/ |
| 129 |
status_t open(const io::Path *file); |
| 130 |
|
| 131 |
/** |
| 132 |
* Wrap memory buffer with stream reader |
| 133 |
* @param buf data contents |
| 134 |
* @param count size of data |
| 135 |
* @return status of operation |
| 136 |
*/ |
| 137 |
status_t wrap(const void *buf, size_t count); |
| 138 |
|
| 139 |
/** |
| 140 |
* Wrap memory buffer with stream reader |
| 141 |
* @param buf data contents |
| 142 |
* @param count size of data |
| 143 |
* @param drop drop operation on close() |
| 144 |
* @return status of operation |
| 145 |
*/ |
| 146 |
status_t wrap(void *buf, size_t count, lsp_memdrop_t drop); |
| 147 |
|
| 148 |
/** |
| 149 |
* Wrap input stream |
| 150 |
* @param is input stream |
| 151 |
* @param flags actions on the input stream after close() |
| 152 |
* @return status of operation |
| 153 |
*/ |
| 154 |
status_t wrap(io::IInStream *is, size_t flags); |
| 155 |
|
| 156 |
/** |
| 157 |
* Close data reader |
| 158 |
* @return status of operation |
| 159 |
*/ |
| 160 |
status_t close(); |
| 161 |
|
| 162 |
/** |
| 163 |
* Get current object stream version |
| 164 |
* @return current object stream version |
| 165 |
*/ |
| 166 |
inline ssize_t version() const { return nVersion; } |
| 167 |
|
| 168 |
status_t current_token(); |
| 169 |
|
| 170 |
status_t read_byte(uint8_t *dst); |
| 171 |
status_t read_byte(int8_t *dst); |
| 172 |
status_t read_short(uint16_t *dst); |
| 173 |
status_t read_short(int16_t *dst); |
| 174 |
status_t read_int(uint32_t *dst); |
| 175 |
status_t read_int(int32_t *dst); |
| 176 |
status_t read_long(uint64_t *dst); |
| 177 |
status_t read_long(int64_t *dst); |
| 178 |
status_t read_float(float_t *dst); |
| 179 |
status_t read_double(double_t *dst); |
| 180 |
status_t read_char(lsp_utf16_t *dst); |
| 181 |
status_t read_bool(bool_t *dst); |
| 182 |
|
| 183 |
status_t read_bytes(uint8_t *dst, size_t count); |
| 184 |
status_t read_bytes(int8_t *dst, size_t count); |
| 185 |
status_t read_shorts(uint16_t *dst, size_t count); |
| 186 |
status_t read_shorts(int16_t *dst, size_t count); |
| 187 |
status_t read_ints(uint32_t *dst, size_t count); |
| 188 |
status_t read_ints(int32_t *dst, size_t count); |
| 189 |
status_t read_longs(uint64_t *dst, size_t count); |
| 190 |
status_t read_longs(int64_t *dst, size_t count); |
| 191 |
status_t read_floats(float_t *dst, size_t count); |
| 192 |
status_t read_doubles(double_t *dst, size_t count); |
| 193 |
status_t read_chars(lsp_utf16_t *dst, size_t count); |
| 194 |
status_t read_bools(bool_t *dst, size_t count); |
| 195 |
|
| 196 |
status_t read_utf(LSPString *dst); |
| 197 |
|
| 198 |
status_t read_object(Object **dst); |
| 199 |
status_t read_array(RawArray **dst); |
| 200 |
status_t read_string(String **dst); |
| 201 |
status_t read_string(LSPString *dst); |
| 202 |
status_t read_enum(Enum **dst); |
| 203 |
status_t read_class_descriptor(ObjectStreamClass **dst); |
| 204 |
}; |
| 205 |
|
| 206 |
} /* namespace java */ |
| 207 |
} /* namespace lsp */ |
| 208 |
|
| 209 |
#endif /* LSP_PLUG_IN_FMT_JAVA_OBJECTSTREAM_H_ */ |