MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / serializeLimit

Method serializeLimit

lib/loader/serialize/serial_type.cpp:125–163  ·  view source on GitHub ↗

Serialize limit. See "include/loader/serialize.h".

Source from the content-addressed store, hash-verified

123
124// Serialize limit. See "include/loader/serialize.h".
125Expect<void>
126Serializer::serializeLimit(const AST::Limit &Lim,
127 std::vector<uint8_t> &OutVec) const noexcept {
128 // Limit: 0x00 + min:u32
129 // |0x01 + min:u32 + max:u32
130 // |0x02 + min:u32 (shared, invalid)
131 // |0x03 + min:u32 + max:u32 (shared)
132 // |0x04 + min:u64
133 // |0x05 + min:u64 + max:u64
134 // |0x06 + min:u64
135 // |0x07 + min:u64 + max:u64
136 //
137 // we encode all of them in u64
138 uint8_t Flag = 0;
139 if (Lim.isShared()) {
140 Flag |= 0x02U;
141 }
142 if (Lim.hasMax()) {
143 Flag |= 0x01U;
144 }
145 if (static_cast<AST::Limit::LimitType>(Flag) >=
146 AST::Limit::LimitType::SharedNoMax) {
147 if (Conf.hasProposal(Proposal::Threads)) {
148 if (unlikely(!Lim.hasMax())) {
149 return logSerializeError(ErrCode::Value::SharedMemoryNoMax,
150 ASTNodeAttr::Type_Limit);
151 }
152 } else {
153 return logSerializeError(ErrCode::Value::IntegerTooLarge,
154 ASTNodeAttr::Type_Limit);
155 }
156 }
157 OutVec.push_back(Flag);
158 serializeU64(Lim.getMin(), OutVec);
159 if (Lim.hasMax()) {
160 serializeU64(Lim.getMax(), OutVec);
161 }
162 return {};
163}
164
165// Serialize sub type. See "include/loader/serialize.h".
166Expect<void>

Callers

nothing calls this directly

Calls 6

unlikelyFunction · 0.85
hasMaxMethod · 0.80
hasProposalMethod · 0.80
getMinMethod · 0.80
getMaxMethod · 0.80
isSharedMethod · 0.45

Tested by

no test coverage detected