mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-09-04 08:20:03 +00:00
feat[cpp]: compatible field of inside protocol class
This commit is contained in:
@@ -262,6 +262,9 @@ public abstract class GenerateCppUtils {
|
||||
serializer.writeObject(cppBuilder, "message->" + field.getName(), 3, field, fieldRegistration);
|
||||
}
|
||||
}
|
||||
if (registration.isCompatible()) {
|
||||
cppBuilder.append(TAB + TAB + TAB).append(StringUtils.format("buffer.adjustPadding({}, beforeWriteIndex);", registration.getPredictionLength())).append(LS);
|
||||
}
|
||||
return cppBuilder.toString();
|
||||
}
|
||||
|
||||
@@ -275,18 +278,16 @@ public abstract class GenerateCppUtils {
|
||||
var field = fields[i];
|
||||
var fieldRegistration = fieldRegistrations[i];
|
||||
|
||||
if (field.isAnnotationPresent(Compatible.class)) {
|
||||
cppBuilder.append(TAB + TAB + TAB).append(StringUtils.format("if (!buffer.isReadable()) { return packet; }")).append(LS);
|
||||
}
|
||||
if (field.isAnnotationPresent(Compatible.class)) {
|
||||
cppBuilder.append(TAB + TAB + TAB).append("if (buffer.compatibleRead(beforeReadIndex, length)) {").append(LS);
|
||||
var compatibleReadObject = cppSerializer(fieldRegistration.serializer()).readObject(cppBuilder, 4, field, fieldRegistration);
|
||||
cppBuilder.append(TAB + TAB + TAB);
|
||||
cppBuilder.append(TAB + TAB + TAB + TAB);
|
||||
if (ProtocolManager.isProtocolClass(field.getType())) {
|
||||
cppBuilder.append(StringUtils.format("packet->{} = *{};", field.getName(), compatibleReadObject));
|
||||
} else {
|
||||
cppBuilder.append(StringUtils.format("packet->{} = {};", field.getName(), compatibleReadObject));
|
||||
}
|
||||
cppBuilder.append(LS).append(TAB + TAB + TAB).append("}").append(LS);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,10 +46,15 @@ namespace zfoo {
|
||||
|
||||
IProtocol *read(ByteBuffer &buffer) override {
|
||||
auto *packet = new {}();
|
||||
if (!buffer.readBool()) {
|
||||
auto length = buffer.readInt();
|
||||
if (length == 0) {
|
||||
return packet;
|
||||
}
|
||||
auto beforeReadIndex = buffer.readerIndex();
|
||||
{}
|
||||
if (length > 0) {
|
||||
buffer.readerIndex(beforeReadIndex + length);
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user