Skip to content

Commit

Permalink
Merge pull request #223 from sismais/feature/219-Add-TFieldType.ftBytes
Browse files Browse the repository at this point in the history
#219 - Implementado tratamento para FieldType = ftBytes
  • Loading branch information
viniciussanchez committed Dec 28, 2023
2 parents 7c8fb82 + 75d3b73 commit f965583
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/DataSet.Serialize.Export.pas
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ function TDataSetSerialize.ToJSONObject: TJSONObject;
function TDataSetSerialize.DataSetToJSONArray(const ADataSet: TDataSet; const IsChild: Boolean; const IsValue: Boolean = True; const IsEncodeBlob: Boolean = True): TJSONArray;
var
LBookMark: TBookmark;
LHexString: String;
LByteValue: Byte;
begin
Result := TJSONArray.Create;
if ADataSet.IsEmpty then
Expand Down Expand Up @@ -238,6 +240,13 @@ function TDataSetSerialize.DataSetToJSONArray(const ADataSet: TDataSet; const Is
else
Result.Add(ADataSet.Fields[0].AsString);
end;
TFieldType.ftVarBytes, TFieldType.ftBytes:
begin
LHexString := EmptyStr;
for LByteValue in ADataSet.Fields[0].AsBytes do
LHexString := LHexString + IntToHex(LByteValue, 2);
Result.Add(LHexString);
end
else
raise EDataSetSerializeException.CreateFmt(FIELD_TYPE_NOT_FOUND, [ADataSet.Fields[0].FieldName]);
end;
Expand Down Expand Up @@ -370,7 +379,7 @@ function TDataSetSerialize.DataSetToJSONObject(const ADataSet: TDataSet; const A
{$ENDIF}
TFieldType.ftGraphic, TFieldType.ftBlob, TFieldType.ftOraBlob, TFieldType.ftOraClob{$IF NOT DEFINED(FPC)}, TFieldType.ftStream{$ENDIF}:
Result.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(LKey, TJSONString.Create(IfThen(FEncodeBase64Blob, EncodingBlobField(LField), LField.AsString)));
TFieldType.ftVarBytes:
TFieldType.ftVarBytes, TFieldType.ftBytes:
begin
LHexString := EmptyStr;
for LByteValue in LField.AsBytes do
Expand Down
2 changes: 1 addition & 1 deletion src/DataSet.Serialize.Import.pas
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ procedure TJSONSerialize.JSONObjectToDataSet(const AJSONObject: TJSONObject; con
LField.AsString := LJSONValue.Value;
end;
end;
TFieldType.ftVarBytes:
TFieldType.ftVarBytes, TFieldType.ftBytes:
begin
SetLength(LBytes, Length(LJSONValue.Value) div 2);
LHex := 1;
Expand Down

0 comments on commit f965583

Please sign in to comment.