Skip to content
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

Decoder: Support for nested mixed-type arrays #87

Merged
merged 6 commits into from
May 16, 2024
Merged

Conversation

alexejk
Copy link
Owner

@alexejk alexejk commented May 16, 2024

Updating decoder's logic for handling slices in order to support nested []any types decoding.

This in particular happens when response contains arrays of mixed types including multi-level nested mixed type arrays, such as:

<?xml version="1.0"?>
<methodResponse>
	<params>
		<param>
			<value><string>OK</string></value>
		</param>
		<param>
			<value><int>200</int></value>
		</param>
		<param>
			<value>
				<array>
					<data>
						<value><i4>200</i4></value>
						<value><array><data><value>Some String</value></data></array></value>
						<value>Server: Sip Express Media Server (5.1.0 (x86_64/Linux)) calls: 0 active/0 total/0 connect/0 min</value>
					</data>
				</array>
			</value>
		</param>
	</params>
</methodResponse>

This kind of response should be handled as

	type Response struct {
		Status string
		Code   int
		Data   []any
	}

However Data could not be processed due to Decoder previously expecting a Slice type (and primitive ones) when handling arrays. This however would cause an issue on the second element of the <array> which happens to be another <array>. With this PR decoder now can properly handle interface type when attempting to parse <array> and thus can handle nested arrays.

Fixes #86

Copy link

sonarcloud bot commented May 16, 2024

Copy link

codecov bot commented May 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.29%. Comparing base (c1e7cf1) to head (78203c0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #87      +/-   ##
==========================================
+ Coverage   77.91%   78.29%   +0.37%     
==========================================
  Files           7        7              
  Lines         575      585      +10     
==========================================
+ Hits          448      458      +10     
  Misses         96       96              
  Partials       31       31              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexejk alexejk merged commit efdc407 into master May 16, 2024
4 checks passed
@alexejk alexejk deleted the nested_mixed_arrays branch May 16, 2024 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failure to produce request with a []any as params
1 participant