MCPcopy Create free account
hub / github.com/GlobedGD/globed2 / encodePayload

Method encodePayload

src/modules/scripting/objects/ExtendedObjectBase.cpp:10–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8ExtendedObjectBase::ExtendedObjectBase() {}
9
10void ExtendedObjectBase::encodePayload(geode::FunctionRef<bool(qn::HeapByteWriter&)>&& writefn) {
11 qn::HeapByteWriter writer;
12 writefn(writer);
13
14 // compute the checksum
15 auto data = writer.written();
16 auto csum = this->computeChecksum(data);
17 writer.writeU8(csum);
18
19 // write the data to the object
20
21 data = writer.written();
22
23 qn::ByteReader reader{data};
24
25 log::debug("Encoding payload: {}", hexEncode(data.data(), data.size()));
26
27 auto locations = std::to_array<void*>({
28 &m_item1Mode,
29 &m_item2Mode,
30 &m_resultType1,
31 &m_resultType2,
32 &m_roundType1,
33 &m_roundType2,
34 &m_signType1,
35 &m_signType2
36 });
37
38 if (reader.remainingSize() > sizeof(uint32_t) * locations.size()) {
39 log::error("Not enough data to fill all fields in FireServerObject! need >= {} bytes of space", reader.remainingSize());
40 return;
41 }
42
43 for (auto locptr : locations) {
44 uint32_t* loc = static_cast<uint32_t*>(locptr);
45
46 if (reader.remainingSize() >= sizeof(uint32_t)) {
47 *loc = *reader.readU32();
48 } else if (reader.remainingSize() > 0) {
49 reader.readBytes(reinterpret_cast<uint8_t*>(loc), reader.remainingSize()).unwrap();
50 } else {
51 // fill the rest with 0s
52 *loc = 0;
53 }
54 }
55}
56
57qn::ByteReader ExtendedObjectBase::_decodePayloadPre(qn::ArrayByteWriter<64>& writer) {
58 // could add other props if not enough space :p

Callers

nothing calls this directly

Calls 3

computeChecksumMethod · 0.95
hexEncodeFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected