Solved CAr WriteString/ReadString

Status
Not open for further replies.

Kyraie

Premium
Premium
Joined
Sep 12, 2024
Messages
52
Solutions
1
Reaction score
12
Points
8
Hey,

Not sure if this has been asked before or if it's easy to understand this, anyways..
I have some issues passing strings through CAr using Serialize, the string is stored without any issues but passing the string results in a empty result.

"Test" is passed as "".

I think i've set the Serialize function correct.
Not sure if I need to pass it in ObjSerializeCpt or ObjSerialize.

Hey There!
Please login and(or) register to see this awesome content today.
 
Solution
Not familiar with m_nMode, is it just by setting the variable normally? ”m_nMode = 0”
nope.
Hey There!
Please login and(or) register to see this awesome content today.

Serialize is just a way to store/retrieve some values into/from a CAr passed by reference. Is a way to facilitate writing/reading data in a CAr. Something that you have already implemented correctly in your struct
Note that this implementation makes a call to ar.IsStoring() to know whether it is writing or reading data to the CAr
Hey There!
Please login and(or) register to see this awesome content today.
The implementation of serialize/deserialize is correct, and I believe that strTitle is no longer empty(strTitle[0] = '\0') when you call serialize .

Check that the CAr has m_nMode set to store (0) when EQUIP_SWITCH::Serialize is called.
Usually this condition is already true after creating a new array, or using macros BEFORESENDDUAL, BEFORESENDSOLE etc.
Maybe you are reusing a CAr that is in load mode....
 
Last edited:
The implementation of serialize/deserialize is correct, and I believe that strTitle is no longer empty(strTitle[0] = '\0') when you call serialize .

Check that the CAr has m_nMode set to store (0) when EQUIP_SWITCH::Serialize is called.
Usually this condition is already true after creating a new array, or using macros BEFORESENDDUAL, BEFORESENDSOLE etc.
Maybe you are reusing a CAr that is in load mode....
Not familiar with m_nMode, is it just by setting the variable normally? ”m_nMode = 0”
 
Not familiar with m_nMode, is it just by setting the variable normally? ”m_nMode = 0”
nope.
Hey There!
Please login and(or) register to see this awesome content today.

Serialize is just a way to store/retrieve some values into/from a CAr passed by reference. Is a way to facilitate writing/reading data in a CAr. Something that you have already implemented correctly in your struct
Note that this implementation makes a call to ar.IsStoring() to know whether it is writing or reading data to the CAr
Hey There!
Please login and(or) register to see this awesome content today.

m_nMode automatically defined when creating the CAr..:
Hey There!
Please login and(or) register to see this awesome content today.

When we declare a new CAr (usually called ar) inside a function, or use the macros BEFORESENDDUAL, BEFORESENDSOLE etc, we are creating a new CAr, which will use the will be set to write mode by default and will use internal buffer m_lpBuf to store the data.
Hey There!
Please login and(or) register to see this awesome content today.


On the other side...
Hey There!
Please login and(or) register to see this awesome content today.
Could you change something in your structure to force writing? Theoretically yes, but it is not the right thing to do, after all your structure is correct.
Changing m_nMode manually should never be used, as it would probably be necessary to change the position of m_lpBufferStart , etc... in short it would probably overwrite data or change the correct position of the pointer to read remaining data.

I'm assuming you've already written in your strTitle the title you want to receive, so, what may be happening is that you are using a CAr that is in reading mode (which was started with a buffer received from somewhere), and not a new CAr to write the data.

If you can/want, post the parts where you create and send the package, as well as the parts where you process it back.Because, your struct EQUIP_SWITCH seems to be correct to me, with a correct implementation of serialize and initialization of strTitle as an empty string.
 
Last edited:
  • Like
Reactions: zOmbie and Kyraie
Solution
The issue is that all data is passed through except the strTitle, data is retrieved on the receiving end without issues to insert into the database. I’m wondering why the data gets lost on the receiving end, does it have to do with this or would it be something else?

I’ll check up on this as soon as I get home atleast, this was very useful information
 
If all data is being read correctly (and probably using the 'serialize' function) to send/receive the data, it is likely that the EQUIP_SWITCH struct used to serialize the data has the 'serialize' function called before the strTitle member is defined, or, for some reason, it is being written in the wrong way, keeping the first byte of the string as '\0' , preventing it from being written in the WriteString method.
Data should not be lost along the way, since it is written and read sequentially in CAr. If there is data corruption, the other members would not be read correctly.
 
So it appears when writing this code 6 in the morning you tend to forget stuff when adding the serialize function instead of sending the data through AR straight.
It was never set to use the Serialize function, all tho reading through the information you sent definitely educated me further on AR. So I appreciate the education!
 
Status
Not open for further replies.