Skip to content

Commit cab2aad

Browse files
committed
fix: strip onvif: namespace prefix from XML struct tags for correct unmarshaling
Go's encoding/xml does not match namespace prefixes in struct tags — it matches full namespace URIs. The tags `xml:"onvif:Encoding"` never matched camera responses like `<tt:Encoding>H264</tt:Encoding>` where tt maps to http://www.onvif.org/ver10/schema, causing all response fields (Encoding, Resolution, BitrateLimit, etc.) to unmarshal as zero values. Removing the prefix lets Go match by local name regardless of the namespace prefix the camera uses (tt:, onvif:, or none). Fixes: use-go#29 Fixes: use-go#52
1 parent 67386c9 commit cab2aad

3 files changed

Lines changed: 292 additions & 292 deletions

File tree

device/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ type AddScopesResponse struct {
238238
//TODO: One or more repetitions
239239
type RemoveScopes struct {
240240
XMLName string `xml:"tds:RemoveScopes"`
241-
ScopeItem xsd.AnyURI `xml:"onvif:ScopeItem"`
241+
ScopeItem xsd.AnyURI `xml:"ScopeItem"`
242242
}
243243

244244
type RemoveScopesResponse struct {
@@ -545,7 +545,7 @@ type AddIPAddressFilterResponse struct {
545545

546546
type RemoveIPAddressFilter struct {
547547
XMLName string `xml:"tds:RemoveIPAddressFilter"`
548-
IPAddressFilter onvif.IPAddressFilter `xml:"onvif:IPAddressFilter"`
548+
IPAddressFilter onvif.IPAddressFilter `xml:"IPAddressFilter"`
549549
}
550550

551551
type RemoveIPAddressFilterResponse struct {

ptz/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ type ModifyPresetTourResponse struct {
252252
type OperatePresetTour struct {
253253
XMLName string `xml:"tptz:OperatePresetTour"`
254254
ProfileToken onvif.ReferenceToken `xml:"tptz:ProfileToken"`
255-
PresetTourToken onvif.ReferenceToken `xml:"onvif:PresetTourToken"`
256-
Operation onvif.PTZPresetTourOperation `xml:"onvif:Operation"`
255+
PresetTourToken onvif.ReferenceToken `xml:"PresetTourToken"`
256+
Operation onvif.PTZPresetTourOperation `xml:"Operation"`
257257
}
258258

259259
type OperatePresetTourResponse struct {

0 commit comments

Comments
 (0)