commit a27f2f8b5d1de78c44c630ce88566d59176ed413 parent 5eb8745e2045b6db54ac3bec6b9b0cf82529a33b Author: Oliver Lowe <o@olowe.co> Date: Thu, 2 May 2024 16:19:08 +1000 internal/scte35: remove all xml, json encoding logic This doesn't just remove a bunch of lines, it also makes the code lighter on the page. Now I see that the tests cannot verify binary encoding behaviour without first doing non-deterministic serialising to JSON and XML! I'm not sure that JSON and XML are that important anyway; an ESAM endpoint I worked with and HLS use base64-encoded binary. May as well verify the binary first, then maybe support other ways to serialise. Diffstat:
18 files changed, 110 insertions(+), 335 deletions(-)
diff --git a/internal/scte35/audio_descriptor.go b/internal/scte35/audio_descriptor.go @@ -31,17 +31,11 @@ const AudioDescriptorTag = 0x04 // support dynamic signaling (e.g., signaling of audio language changes) and // with legacy audio formats that do not support dynamic signaling. type AudioDescriptor struct { - XMLName struct{} `xml:"http://www.scte.org/schemas/35 AudioDescriptor" json:"-"` - JSONType uint32 `xml:"-" json:"type"` - AudioChannels []AudioChannel `xml:"http://www.scte.org/schemas/35 AudioChannel" json:"audioChannels"` + AudioChannels []AudioChannel } // Tag returns the splice_descriptor_tag. -func (sd *AudioDescriptor) Tag() uint32 { - // ensure JSONType is set - sd.JSONType = AudioDescriptorTag - return AudioDescriptorTag -} +func (sd *AudioDescriptor) Tag() uint32 { return AudioDescriptorTag } // decode updates this SpliceDescriptor from binary. func (sd *AudioDescriptor) decode(b []byte) error { @@ -122,11 +116,11 @@ func (sd *AudioDescriptor) writeTo(t *table) { // AudioChannel collects the audio PID details. type AudioChannel struct { - ComponentTag uint32 `xml:"componentTag,attr" json:"componentTag"` - ISOCode string `xml:"ISOCode,attr" json:"isoCode"` - BitStreamMode uint32 `xml:"BitStreamMode,attr" json:"bitStreamMode"` - NumChannels uint32 `xml:"NumChannels,attr" json:"numChannels"` - FullSrvcAudio bool `xml:"FullSrvcAudio,attr" json:"fullSrvcAudio"` + ComponentTag uint32 + ISOCode string + BitStreamMode uint32 + NumChannels uint32 + FullSrvcAudio bool } // length returns audio_channel length. diff --git a/internal/scte35/avail_descriptor.go b/internal/scte35/avail_descriptor.go @@ -33,17 +33,11 @@ const AvailDescriptorTag = 0x00 // used in analog systems for ad insertion. This descriptor is intended only // for use with a splice_insert() command, within a splice_info_section. type AvailDescriptor struct { - XMLName struct{} `xml:"http://www.scte.org/schemas/35 AvailDescriptor" json:"-"` - JSONType uint32 `xml:"-" json:"type"` - ProviderAvailID uint32 `xml:"providerAvailId,attr" json:"providerAvailId"` + ProviderAvailID uint32 } // Tag returns the splice_descriptor_tag. -func (sd *AvailDescriptor) Tag() uint32 { - // ensure JSONType is set - sd.JSONType = AvailDescriptorTag - return AvailDescriptorTag -} +func (sd *AvailDescriptor) Tag() uint32 { return AvailDescriptorTag } // writeTo the given table. func (sd *AvailDescriptor) writeTo(t *table) { diff --git a/internal/scte35/bandwidth_reservation.go b/internal/scte35/bandwidth_reservation.go @@ -32,17 +32,10 @@ const BandwidthReservationType = 0x07 // expected that it will be carried through the entire transmission chain and it // should be a private descriptor that is utilized only by the bandwidth // reservation process. -type BandwidthReservation struct { - XMLName struct{} `xml:"http://www.scte.org/schemas/35 BandwidthReservation" json:"-"` - JSONType uint32 `xml:"-" json:"type"` -} +type BandwidthReservation struct {} // Type returns the splice_command_type. -func (cmd *BandwidthReservation) Type() uint32 { - // ensure JSONType is set - cmd.JSONType = BandwidthReservationType - return BandwidthReservationType -} +func (cmd *BandwidthReservation) Type() uint32 { return BandwidthReservationType } // decode a binary bandwidth_reservation. func (cmd *BandwidthReservation) decode(b []byte) error { diff --git a/internal/scte35/delivery_restrictions.go b/internal/scte35/delivery_restrictions.go @@ -26,10 +26,10 @@ const ( // DeliveryRestrictions contains the specific delivery restriction flags as // defined within the SegmentationDescriptorType XML schema definition. type DeliveryRestrictions struct { - ArchiveAllowedFlag bool `xml:"archiveAllowedFlag,attr" json:"archiveAllowedFlag"` - WebDeliveryAllowedFlag bool `xml:"webDeliveryAllowedFlag,attr" json:"webDeliveryAllowedFlag"` - NoRegionalBlackoutFlag bool `xml:"noRegionalBlackoutFlag,attr" json:"noRegionalBlackoutFlag"` - DeviceRestrictions uint32 `xml:"deviceRestrictions,attr" json:"deviceRestrictions"` + ArchiveAllowedFlag bool + WebDeliveryAllowedFlag bool + NoRegionalBlackoutFlag bool + DeviceRestrictions uint32 } // deviceRestrictionsName returns the human-readable name for the diff --git a/internal/scte35/dtmf_descriptor.go b/internal/scte35/dtmf_descriptor.go @@ -30,10 +30,8 @@ const DTMFDescriptorTag = 0x01 // device to generate a legacy analog DTMF sequence based on a // splice_info_section being received. type DTMFDescriptor struct { - XMLName struct{} `xml:"http://www.scte.org/schemas/35 DTMFDescriptor" json:"-"` - JSONType uint32 `xml:"-" json:"type"` - Preroll uint32 `xml:"preroll,attr" json:"preroll"` - DTMFChars string `xml:"chars,attr" json:"chars"` + Preroll uint32 + DTMFChars string } // writeTo the given table. @@ -49,11 +47,7 @@ func (sd *DTMFDescriptor) writeTo(t *table) { } // Tag returns the splice_descriptor_tag. -func (sd *DTMFDescriptor) Tag() uint32 { - // ensure JSONType is set - sd.JSONType = DTMFDescriptorTag - return DTMFDescriptorTag -} +func (sd *DTMFDescriptor) Tag() uint32 { return DTMFDescriptorTag } // decode updates this splice_descriptor from binary. func (sd *DTMFDescriptor) decode(b []byte) error { diff --git a/internal/scte35/encrypted_packet.go b/internal/scte35/encrypted_packet.go @@ -14,8 +14,8 @@ const ( type EncryptedPacket struct { // Specifies which cipher is used. // See SCTE 35 section 11.3. - EncryptionAlgorithm uint32 `xml:"encryptionAlgorithm,attr,omitempty" json:"encryptionAlgorithm,omitempty"` - CWIndex uint32 `xml:"cwIndex,attr,omitempty" json:"cwIndex,omitempty"` + EncryptionAlgorithm uint32 + CWIndex uint32 } // cipher is a 6-bit field specifying the algorithm used to encrypt diff --git a/internal/scte35/private_command.go b/internal/scte35/private_command.go @@ -18,7 +18,6 @@ package scte35 import ( "encoding/binary" - "encoding/xml" "fmt" "github.com/bamiaux/iobit" @@ -33,10 +32,8 @@ const PrivateCommandType = 0xFF // should skip any splice_info_section() messages containing private_command() // structures with unknown identifiers. type PrivateCommand struct { - XMLName xml.Name `xml:"http://www.scte.org/schemas/35 PrivateCommand" json:"-"` - JSONType uint32 `xml:"-" json:"type"` - Identifier uint32 `xml:"identifier,attr" json:"identifier"` - PrivateBytes Bytes `xml:",chardata" json:"privateBytes"` + Identifier uint32 + PrivateBytes Bytes } // IdentifierString returns the identifier as a string. @@ -47,11 +44,7 @@ func (cmd *PrivateCommand) IdentifierString() string { } // Type returns the splice_command_type. -func (cmd *PrivateCommand) Type() uint32 { - // ensure JSONType is set - cmd.JSONType = PrivateCommandType - return PrivateCommandType -} +func (cmd *PrivateCommand) Type() uint32 { return PrivateCommandType } // decode a binary private_command. func (cmd *PrivateCommand) decode(b []byte) error { diff --git a/internal/scte35/private_descriptor.go b/internal/scte35/private_descriptor.go @@ -25,11 +25,9 @@ import ( // PrivateDescriptor encapsulates the contents of non-CUEI descriptors type PrivateDescriptor struct { - XMLName struct{} `xml:"http://www.scte.org/schemas/35 PrivateDescriptor" json:"-"` - JSONType uint32 `xml:"-" json:"type"` - PrivateTag uint32 `xml:"tag,attr" json:"tag"` - Identifier uint32 `xml:"identifier,attr" json:"identifier"` - PrivateBytes Bytes `xml:",chardata" json:"privateBytes"` + PrivateTag uint32 + Identifier uint32 + PrivateBytes Bytes } // IdentifierString returns the identifier as a string @@ -40,11 +38,7 @@ func (sd *PrivateDescriptor) IdentifierString() string { } // Tag returns the splice_descriptor_tag. -func (sd *PrivateDescriptor) Tag() uint32 { - // ensure JSONType is set - sd.JSONType = sd.PrivateTag - return sd.PrivateTag -} +func (sd *PrivateDescriptor) Tag() uint32 { return sd.PrivateTag } // decode updates this splice_descriptor from binary. func (sd *PrivateDescriptor) decode(b []byte) error { diff --git a/internal/scte35/scte35.go b/internal/scte35/scte35.go @@ -99,8 +99,8 @@ func TicksToDuration(ticks uint64) time.Duration { // used to give the splicer an indication of when the break will be over and // when the network In Point will occur. type BreakDuration struct { - AutoReturn bool `xml:"autoReturn,attr" json:"autoReturn"` - Duration uint64 `xml:"duration,attr" json:"duration"` + AutoReturn bool + Duration uint64 } // Bytes is a byte array. diff --git a/internal/scte35/segmentation_descriptor.go b/internal/scte35/segmentation_descriptor.go @@ -170,19 +170,17 @@ const ( // in advance of the signaled splice_time() to permit the insertion device to // place the splice_info_section( ) accurately. type SegmentationDescriptor struct { - XMLName struct{} `xml:"http://www.scte.org/schemas/35 SegmentationDescriptor" json:"-"` - JSONType uint32 `xml:"-" json:"type"` - DeliveryRestrictions *DeliveryRestrictions `xml:"http://www.scte.org/schemas/35 DeliveryRestrictions" json:"deliveryRestrictions,omitempty"` - SegmentationUPIDs []SegmentationUPID `xml:"http://www.scte.org/schemas/35 SegmentationUpid" json:"segmentationUpids,omitempty"` - Components []SegmentationDescriptorComponent `xml:"http://www.scte.org/schemas/35 Component" json:"components,omitempty"` - SegmentationEventID uint32 `xml:"segmentationEventId,attr,omitempty" json:"segmentationEventId,omitempty"` - SegmentationEventCancelIndicator bool `xml:"segmentationEventCancelIndicator,attr,omitempty" json:"segmentationEventCancelIndicator,omitempty"` - SegmentationDuration *uint64 `xml:"segmentationDuration,attr" json:"segmentationDuration,omitempty"` - SegmentationTypeID uint32 `xml:"segmentationTypeId,attr,omitempty" json:"segmentationTypeId,omitempty"` - SegmentNum uint32 `xml:"segmentNum,attr,omitempty" json:"segmentNum,omitempty"` - SegmentsExpected uint32 `xml:"segmentsExpected,attr,omitempty" json:"segmentsExpected,omitempty"` - SubSegmentNum *uint32 `xml:"subSegmentNum,attr" json:"subSegmentNum,omitempty"` - SubSegmentsExpected *uint32 `xml:"subSegmentsExpected,attr" json:"subSegmentsExpected,omitempty"` + DeliveryRestrictions *DeliveryRestrictions + SegmentationUPIDs []SegmentationUPID + Components []SegmentationDescriptorComponent + SegmentationEventID uint32 + SegmentationEventCancelIndicator bool + SegmentationDuration *uint64 + SegmentationTypeID uint32 + SegmentNum uint32 + SegmentsExpected uint32 + SubSegmentNum *uint32 + SubSegmentsExpected *uint32 } // Name returns the human-readable string for the segmentation_type_id. @@ -286,11 +284,7 @@ func (sd *SegmentationDescriptor) Name() string { } // Tag returns the splice_descriptor_tag. -func (sd *SegmentationDescriptor) Tag() uint32 { - // ensure JSONType is set - sd.JSONType = SegmentationDescriptorTag - return SegmentationDescriptorTag -} +func (sd *SegmentationDescriptor) Tag() uint32 { return SegmentationDescriptorTag } // DeliveryNotRestrictedFlag returns the delivery_not_restricted_flag. func (sd *SegmentationDescriptor) DeliveryNotRestrictedFlag() bool { @@ -605,6 +599,6 @@ func (sd *SegmentationDescriptor) writeTo(t *table) { // SegmentationDescriptorComponent describes the Component element contained // within the SegmentationDescriptorType XML schema definition. type SegmentationDescriptorComponent struct { - Tag uint32 `xml:"componentTag,attr" json:"componentTag"` - PTSOffset uint64 `xml:"ptsOffset,attr" json:"ptsOffset"` + Tag uint32 + PTSOffset uint64 } diff --git a/internal/scte35/segmentation_upid.go b/internal/scte35/segmentation_upid.go @@ -115,11 +115,11 @@ func NewSegmentationUPID(upidType uint32, buf []byte) SegmentationUPID { // SegmentationUPID is used to express a UPID in an XML document. type SegmentationUPID struct { - Type uint32 `xml:"segmentationUpidType,attr" json:"segmentationUpidType"` - FormatIdentifier *uint32 `xml:"formatIdentifier,attr,omitempty" json:"formatIdentifier,omitempty"` - Value string `xml:",chardata" json:"value"` + Type uint32 + FormatIdentifier *uint32 + Value string // Deprecated: no longer used and will be removed in a future release - Format string `xml:"-" json:"-"` + Format string } // Name returns the name for the segmentation_upid_type. diff --git a/internal/scte35/splice_descriptor.go b/internal/scte35/splice_descriptor.go @@ -16,13 +16,7 @@ package scte35 -import ( - "encoding/json" - "encoding/xml" - "fmt" - - "github.com/bamiaux/iobit" -) +import "github.com/bamiaux/iobit" const ( // CUEIdentifier is 32-bit number used to identify the owner of the @@ -76,81 +70,6 @@ type SpliceDescriptor interface { // SpliceDescriptors is a slice of SpliceDescriptor. type SpliceDescriptors []SpliceDescriptor -// UnmarshalJSON decodes a JSON array into a slice of SpliceDescriptors. -func (sds *SpliceDescriptors) UnmarshalJSON(data []byte) error { - // split the array into individual JSON objects - var items []json.RawMessage - if err := json.Unmarshal(data, &items); err != nil { - return err - } - - // slice to hold decoded splice descriptors - results := make([]SpliceDescriptor, len(items)) - - // struct to extract splice descriptor type data - type sdtype struct { - Identifier uint32 `json:"identifier"` - Type uint32 `json:"type"` - } - - // decode each item - for i := range items { - sdt := sdtype{Identifier: CUEIdentifier} - if err := json.Unmarshal(items[i], &sdt); err != nil { - return err - } - - sd := NewSpliceDescriptor(sdt.Identifier, sdt.Type) - if err := json.Unmarshal(items[i], &sd); err != nil { - return err - } - - results[i] = sd - } - - // replace the slice - *sds = results - return nil -} - -// UnmarshalXML decodes an XML payload into a slice of SpliceDescriptors. -// -// Unlike UnmarshalJSON, this function is executed once per SpliceDescriptor -// rather than once per slice. -func (sds *SpliceDescriptors) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { - var tmp SpliceDescriptors - - // determine the type - var sd SpliceDescriptor - switch start.Name.Local { - case "AudioDescriptor": - sd = &AudioDescriptor{} - case "AvailDescriptor": - sd = &AvailDescriptor{} - case "DTMFDescriptor": - sd = &DTMFDescriptor{} - case "PrivateDescriptor": - sd = &PrivateDescriptor{} - case "SegmentationDescriptor": - sd = &SegmentationDescriptor{} - case "TimeDescriptor": - sd = &TimeDescriptor{} - default: - return fmt.Errorf("unsupported splice_descriptor tag: %s", start.Name.Local) - } - - // decode it - if err := d.DecodeElement(&sd, &start); err != nil { - return err - } - - // add it to the slice - tmp = append(*sds, sd) - *sds = tmp - - return nil -} - // decodeSpliceDescriptors returns a slice of SpliceDescriptors from decoding // the supplied byte array. func decodeSpliceDescriptors(b []byte) ([]SpliceDescriptor, error) { diff --git a/internal/scte35/splice_info_section.go b/internal/scte35/splice_info_section.go @@ -20,7 +20,6 @@ import ( "encoding/base64" "encoding/hex" "encoding/json" - "encoding/xml" "errors" "fmt" "time" @@ -56,18 +55,17 @@ const ( // and equal to 0x00 and the payload_unit_start_indicator bit shall be equal to // one (per the requirements of section syntax usage per [MPEG Systems]). type SpliceInfoSection struct { - XMLName struct{} `xml:"http://www.scte.org/schemas/35 SpliceInfoSection"` - EncryptedPacket EncryptedPacket `xml:"http://www.scte.org/schemas/35 EncryptedPacket,omitempty"` - SpliceCommand SpliceCommand `xml:""` - SpliceDescriptors SpliceDescriptors `xml:""` - SAPType uint32 `xml:"sapType,attr"` - PreRollMilliSeconds uint32 `xml:"preRollMilliSeconds,attr,omitempty"` // no corresponding binary field - PTSAdjustment uint64 `xml:"ptsAdjustment,attr,omitempty"` - ProtocolVersion uint32 `xml:"protocolVersion,attr,omitempty"` - Tier uint32 `xml:"tier,attr"` - alignmentStuffing []byte // alignment_stuffing - ecrc32 []byte // decoded e_crc_32 - crc32 []byte // decoded crc_32 + EncryptedPacket EncryptedPacket + SpliceCommand SpliceCommand + SpliceDescriptors SpliceDescriptors + SAPType uint32 + PreRollMilliSeconds uint32 // no corresponding binary field + PTSAdjustment uint64 + ProtocolVersion uint32 + Tier uint32 + alignmentStuffing []byte // alignment_stuffing + ecrc32 []byte // decoded e_crc_32 + crc32 []byte // decoded crc_32 } // Base64 returns the SpliceInfoSection as a base64 encoded string. @@ -283,73 +281,6 @@ func (sis *SpliceInfoSection) Table(prefix, indent string) string { return t.String() } -// MarshalJSON encodes a SpliceInfoSection to JSON. -func (sis *SpliceInfoSection) MarshalJSON() ([]byte, error) { - // ensure JSONTypes are all set before marshalling. These are included in - // each SpliceCommand.Type() and SpliceDescriptor.Tag() implementation. - sis.SpliceCommand.Type() - for i := range sis.SpliceDescriptors { - sis.SpliceDescriptors[i].Tag() - } - - m := map[string]interface{}{ - "encryptedPacket": sis.EncryptedPacket, - "spliceCommand": sis.SpliceCommand, - "sapType": sis.SAPType, - "tier": sis.Tier, - } - if sis.ProtocolVersion > 0 { - m["protocolVersion"] = sis.ProtocolVersion - } - if sis.PTSAdjustment > 0 { - m["ptsAdjustment"] = sis.PTSAdjustment - } - if len(sis.SpliceDescriptors) > 0 { - m["spliceDescriptors"] = sis.SpliceDescriptors - } - return json.Marshal(m) -} - -// UnmarshalJSON decodes a SpliceInfoSection from JSON. -func (sis *SpliceInfoSection) UnmarshalJSON(b []byte) error { - var tmp iSIS - if err := json.Unmarshal(b, &tmp); err != nil { - return err - } - - sis.EncryptedPacket = tmp.EncryptedPacket - sis.SpliceCommand = tmp.SpliceCommand() - sis.SpliceDescriptors = tmp.SpliceDescriptors - if tmp.SAPType != nil { - sis.SAPType = *tmp.SAPType - } else { - sis.SAPType = SAPTypeNotSpecified - } - sis.PTSAdjustment = tmp.PTSAdjustment - sis.ProtocolVersion = tmp.ProtocolVersion - sis.Tier = tmp.Tier - return nil -} - -// UnmarshalXML decodes a SpliceInfoSection from XML. -func (sis *SpliceInfoSection) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { - var tmp iSIS - if err := d.DecodeElement(&tmp, &start); err != nil { - return err - } - sis.EncryptedPacket = tmp.EncryptedPacket - sis.SpliceCommand = tmp.SpliceCommand() - sis.SpliceDescriptors = tmp.SpliceDescriptors - sis.SAPType = SAPTypeNotSpecified - if tmp.SAPType != nil { - sis.SAPType = *tmp.SAPType - } - sis.PTSAdjustment = tmp.PTSAdjustment - sis.ProtocolVersion = tmp.ProtocolVersion - sis.Tier = tmp.Tier - return nil -} - // length returns the expected length of the encoded splice_info_section, in // bytes. func (sis *SpliceInfoSection) length() int { @@ -403,19 +334,19 @@ func (sis *SpliceInfoSection) descriptorLoopLength() int { // iSIS is an internal SpliceInfoSection used to support (un)marshalling // polymorphic fields. type iSIS struct { - EncryptedPacket EncryptedPacket `xml:"http://www.scte.org/schemas/35 EncryptedPacket,omitempty" json:"encryptedPacket,omitempty"` - SpliceCommandRaw json.RawMessage `xml:"-" json:"spliceCommand"` - SpliceNull *SpliceNull `xml:"http://www.scte.org/schemas/35 SpliceNull" json:"-"` - SpliceSchedule *SpliceSchedule `xml:"http://www.scte.org/schemas/35 SpliceSchedule" json:"-"` - SpliceInsert *SpliceInsert `xml:"http://www.scte.org/schemas/35 SpliceInsert" json:"-"` - TimeSignal *TimeSignal `xml:"http://www.scte.org/schemas/35 TimeSignal" json:"-"` - BandwidthReservation *BandwidthReservation `xml:"http://www.scte.org/schemas/35 BandwidthReservation" json:"-"` - PrivateCommand *PrivateCommand `xml:"http://www.scte.org/schemas/35 PrivateCommand" json:"-"` - SpliceDescriptors SpliceDescriptors `xml:",any" json:"spliceDescriptors"` - SAPType *uint32 `xml:"sapType,attr" json:"sapType,omitempty"` - PTSAdjustment uint64 `xml:"ptsAdjustment,attr" json:"ptsAdjustment"` - ProtocolVersion uint32 `xml:"protocolVersion,attr" json:"protocolVersion"` - Tier uint32 `xml:"tier,attr" json:"tier"` + EncryptedPacket EncryptedPacket + SpliceCommandRaw json.RawMessage + SpliceNull *SpliceNull + SpliceSchedule *SpliceSchedule + SpliceInsert *SpliceInsert + TimeSignal *TimeSignal + BandwidthReservation *BandwidthReservation + PrivateCommand *PrivateCommand + SpliceDescriptors SpliceDescriptors + SAPType *uint32 + PTSAdjustment uint64 + ProtocolVersion uint32 + Tier uint32 } // SpliceCommand returns the polymorphic splice_command. diff --git a/internal/scte35/splice_insert.go b/internal/scte35/splice_insert.go @@ -29,18 +29,16 @@ const SpliceInsertType = 0x05 // SpliceInsert is a command shall be sent at least once for every splice // event. type SpliceInsert struct { - XMLName struct{} `xml:"http://www.scte.org/schemas/35 SpliceInsert" json:"-"` - JSONType uint32 `xml:"-" json:"type"` - Program *SpliceInsertProgram `xml:"http://www.scte.org/schemas/35 Program" json:"program,omitempty"` - Components []SpliceInsertComponent `xml:"http://www.scte.org/schemas/35 Component" json:"components,omitempty"` - BreakDuration *BreakDuration `xml:"http://www.scte.org/schemas/35 BreakDuration" json:"breakDuration,omitempty"` - SpliceEventID uint32 `xml:"spliceEventId,attr" json:"spliceEventId,omitempty"` - SpliceEventCancelIndicator bool `xml:"spliceEventCancelIndicator,attr" json:"spliceEventCancelIndicator"` - SpliceImmediateFlag bool `xml:"spliceImmediateFlag,attr" json:"spliceImmediateFlag"` - OutOfNetworkIndicator bool `xml:"outOfNetworkIndicator,attr" json:"outOfNetworkIndicator"` - UniqueProgramID uint32 `xml:"uniqueProgramId,attr" json:"uniqueProgramId,omitempty"` - AvailNum uint32 `xml:"availNum,attr" json:"availNum,omitempty"` - AvailsExpected uint32 `xml:"availsExpected,attr" json:"availsExpected,omitempty"` + Program *SpliceInsertProgram + Components []SpliceInsertComponent + BreakDuration *BreakDuration + SpliceEventID uint32 + SpliceEventCancelIndicator bool + SpliceImmediateFlag bool + OutOfNetworkIndicator bool + UniqueProgramID uint32 + AvailNum uint32 + AvailsExpected uint32 } // DurationFlag returns the duration_flag. @@ -59,10 +57,7 @@ func (cmd *SpliceInsert) TimeSpecifiedFlag() bool { } // Type returns the splice_command_type. -func (cmd *SpliceInsert) Type() uint32 { - cmd.JSONType = SpliceInsertType - return SpliceInsertType -} +func (cmd *SpliceInsert) Type() uint32 { return SpliceInsertType } // writeTo the given table. func (cmd *SpliceInsert) writeTo(t *table) { @@ -288,8 +283,8 @@ func (cmd SpliceInsert) length() int { // SpliceInsertComponent contains the Splice Point in Component Splice Mode. type SpliceInsertComponent struct { - Tag uint32 `xml:"componentTag,attr" json:"componentTag,omitempty"` - SpliceTime *SpliceTime `xml:"http://www.scte.org/schemas/35 SpliceTime" json:"spliceTime,omitempty"` + Tag uint32 + SpliceTime *SpliceTime } // TimeSpecifiedFlag returns the time_specified_flag. @@ -308,7 +303,7 @@ func NewSpliceInsertProgram(ptsTime uint64) *SpliceInsertProgram { // SpliceInsertProgram contains the Splice Point in Program Splice Mode. type SpliceInsertProgram struct { - SpliceTime SpliceTime `xml:"http://www.scte.org/schemas/35 SpliceTime" json:"spliceTime"` + SpliceTime SpliceTime } // TimeSpecifiedFlag returns the time_specified_flag. @@ -318,7 +313,7 @@ func (p *SpliceInsertProgram) TimeSpecifiedFlag() bool { // SpliceTime specifies the time of the splice event. type SpliceTime struct { - PTSTime *uint64 `xml:"ptsTime,attr" json:"ptsTime,omitempty"` + PTSTime *uint64 } // TimeSpecifiedFlag returns true if PTSTime is not nil. diff --git a/internal/scte35/splice_null.go b/internal/scte35/splice_null.go @@ -26,17 +26,10 @@ const SpliceNullType uint32 = 0 // descriptors without having to send one of the other defined commands. This // command may also be used as a “heartbeat message” for monitoring cue // injection equipment integrity and link integrity. -type SpliceNull struct { - XMLName struct{} `xml:"http://www.scte.org/schemas/35 SpliceNull" json:"-"` - JSONType uint32 `xml:"-" json:"type"` -} +type SpliceNull struct{} // Type returns the splice_command_type. -func (cmd *SpliceNull) Type() uint32 { - // ensure JSONType is set - cmd.JSONType = SpliceNullType - return SpliceNullType -} +func (cmd *SpliceNull) Type() uint32 { return SpliceNullType } // decode a binary splice_null. func (cmd *SpliceNull) decode(b []byte) error { diff --git a/internal/scte35/splice_schedule.go b/internal/scte35/splice_schedule.go @@ -30,17 +30,11 @@ const SpliceScheduleType = 0x04 // SpliceSchedule is provided to allow a schedule of splice events to be // conveyed in advance. type SpliceSchedule struct { - XMLName struct{} `xml:"http://www.scte.org/schemas/35 SpliceSchedule" json:"-"` - JSONType uint32 `xml:"-" json:"type"` - Events []Event `xml:"http://www.scte.org/schemas/35 Event" json:"events"` + Events []Event } // Type returns the splice_command_type -func (cmd *SpliceSchedule) Type() uint32 { - // ensure the JSONType is set correctly. - cmd.JSONType = SpliceScheduleType - return SpliceScheduleType -} +func (cmd *SpliceSchedule) Type() uint32 { return SpliceScheduleType } // decode a binary splice_schedule. func (cmd *SpliceSchedule) decode(b []byte) error { @@ -210,15 +204,15 @@ func (cmd *SpliceSchedule) writeTo(t *table) { // Event is a single event within a splice_schedule. type Event struct { - Program *EventProgram `xml:"http://www.scte.org/schemas/35 Program" json:"program"` - Components []EventComponent `xml:"http://www.scte.org/schemas/35 Component" json:"components"` - BreakDuration *BreakDuration `xml:"http://www.scte.org/schemas/35 BreakDuration" json:"breakDuration"` - SpliceEventID uint32 `xml:"spliceEventId,attr" json:"spliceEventId"` - SpliceEventCancelIndicator bool `xml:"spliceEventCancelIndicator,attr" json:"spliceEventCancelIndicator"` - OutOfNetworkIndicator bool `xml:"outOfNetworkIndicator,attr" json:"outOfNetworkIndicator,omitempty"` - UniqueProgramID uint32 `xml:"uniqueProgramId,attr" json:"uniqueProgramId,omitempty"` - AvailNum uint32 `xml:"availNum,attr" json:"availNum,omitempty"` - AvailsExpected uint32 `xml:"availsExpected,attr" json:"availsExpected,omitempty"` + Program *EventProgram + Components []EventComponent + BreakDuration *BreakDuration + SpliceEventID uint32 + SpliceEventCancelIndicator bool + OutOfNetworkIndicator bool + UniqueProgramID uint32 + AvailNum uint32 + AvailsExpected uint32 } // DurationFlag returns the duration_flag. @@ -233,12 +227,11 @@ func (e *Event) ProgramSpliceFlag() bool { // EventComponent contains the Splice Points in Component Splice Mode. type EventComponent struct { - Tag uint32 `xml:"componentTag,attr" json:"componentTag"` - UTCSpliceTime UTCSpliceTime `xml:"utcSpliceTime,attr" json:"utcSpliceTime"` + Tag uint32 + UTCSpliceTime UTCSpliceTime } // EventProgram contains the Splice Point in Program Splice Mode type EventProgram struct { - XMLName struct{} `xml:"http://www.scte.org/schemas/35 Program" json:"-"` - UTCSpliceTime UTCSpliceTime `xml:"utcSpliceTime,attr" json:"utcSpliceTime"` + UTCSpliceTime UTCSpliceTime } diff --git a/internal/scte35/time_descriptor.go b/internal/scte35/time_descriptor.go @@ -32,19 +32,13 @@ const TimeDescriptorTag = 0x03 // time_signal() or splice_insert( ) command. This command may be inserted using // SCTE 104 or by out of band provisioning on the device inserting this message. type TimeDescriptor struct { - XMLName struct{} `xml:"TimeDescriptor" json:"-"` - JSONType uint32 `xml:"-" json:"type"` - TAISeconds uint64 `xml:"taiSeconds,attr" json:"taiSeconds"` - TAINS uint32 `xml:"taiNs,attr" json:"taiNs"` - UTCOffset uint32 `xml:"utcOffset,attr" json:"utcOffset"` + TAISeconds uint64 + TAINS uint32 + UTCOffset uint32 } // Tag returns the splice_descriptor_tag. -func (sd *TimeDescriptor) Tag() uint32 { - // ensure JSONType is set - sd.JSONType = TimeDescriptorTag - return TimeDescriptorTag -} +func (sd *TimeDescriptor) Tag() uint32 { return TimeDescriptorTag } // table returns the tabular description of this TimeDescriptor. func (sd *TimeDescriptor) writeTo(t *table) { diff --git a/internal/scte35/time_signal.go b/internal/scte35/time_signal.go @@ -43,17 +43,11 @@ func NewTimeSignal(ptsTime uint64) *TimeSignal { // time_signal(). The carriage however can be in a different PID than that // carrying the other cue messages used for signaling splice points. type TimeSignal struct { - XMLName struct{} `xml:"http://www.scte.org/schemas/35 TimeSignal" json:"-"` - JSONType uint32 `xml:"-" json:"type"` - SpliceTime SpliceTime `xml:"http://www.scte.org/schemas/35 SpliceTime" json:"spliceTime"` + SpliceTime SpliceTime } // Type returns the splice_command_type. -func (cmd *TimeSignal) Type() uint32 { - // ensure JSONType is set - cmd.JSONType = TimeSignalType - return TimeSignalType -} +func (cmd *TimeSignal) Type() uint32 { return TimeSignalType } // decode a binary time_signal func (cmd *TimeSignal) decode(b []byte) error { @@ -68,7 +62,7 @@ func (cmd *TimeSignal) decode(b []byte) error { } if err := readerError(r); err != nil { - return fmt.Errorf("%s: %w", cmd.XMLName, err) + return fmt.Errorf("%v: %w", cmd, err) } return nil }