-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TCustomSerializer for Simple Type (not for Class) #23
Comments
You're using TValue.Make and TValue.ExtractRawData. This basically marshals your array pointer, not the array content. Your serializer methods can be much easier: function TBytesSerializer.Serialize(
const AValue: TValue;
ANeonObject: TNeonRttiObject;
AContext: ISerializerContext
): TJSONValue;
var
LBytes: TBytes;
LBase64: string;
begin
LBytes := AValue.AsType<TBytes>();
LBase64 := TBase64.Encode(LBytes);
Result := TJSONString.Create(LBase64);
end;
function TBytesSerializer.Deserialize(
AValue: TJSONValue;
const AData: TValue;
ANeonObject: TNeonRttiObject;
AContext: IDeserializerContext
): TValue;
var
LBytes: TBytes;
begin
LBytes := TBase64.Decode(AValue.Value);
Result := TValue.From(LBytes);
end; I have attached your modified unit and a few testcases here: It shows it will also work with PS: No testcases yet on how it handles invalid Base64 strings 😉 PPS: Neon handles TBytes just fine. Why are you implementing a custom Base64 encoder/decoder? To save space? |
Hi, Best regards. |
Please how to implement TCustomSerializer for TBytes?
The content of TBytes would be a container for a Binary Data, Encrepted Data, ... So marshaling TBytes is made by Base64 encoding/decoding.
Best regards.
The text was updated successfully, but these errors were encountered: