Swiftpack.co -  theRealRobG/SCTE35Parser as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
A Swift implemented abstraction of SCTE-35 messages; in particular the Splice Info Section type.
.package(url: "https://github.com/theRealRobG/SCTE35Parser.git", from: "0.3.1")


SCTE35Parser aims to provide an easy to use, Swift implemented abstraction of SCTE-35 messages, in particular the Splice Info Section type. The 2020 SCTE-25 specification was used and is included as part of the repository.

One of the design goals of the abstraction was to make it more "Swifty", in the sense of having the abstraction more type-safe, by eliminating from the public abstraction a lot of the specified information used just for parsing, and translating it instead into more normal Swift concepts, such as optionals, enums, etc. For example, the specification includes many "flags" used to determine if the next section needs to be parsed; in these cases the flag is not publicised and instead the following section is exposed as an Optional on the public abstraction.


The primary integration point to the framework is the SpliceInfoSection struct.

Given a base64 encoded SCTE-35 message, the SpliceInfoSection offers an init(base64String: String) throws.

let base64String = "/DA0AAAAAAAA///wBQb+cr0AUAAeAhxDVUVJSAAAjn/PAAGlmbAICAAAAAAsoKGKNAIAmsnRfg=="
let spliceInfoSection = try SpliceInfoSection(base64String: base64String)

Errors can be thrown if there are some issues with the provided SCTE-35 message that invalidate the parsing. If an error is thrown it will be a SCTE35ParserError. This is a wrapper struct that includes the thrown error, as well as the first "non-fatal" error that was stored during parsing. When using the SCTE35ParserError as NSError, the underlyingError will be stored in userInfo[NSUnderlyingErrorKey].

The parser also keeps a storage of nonFatalErrors. The idea here is that there may be some inconsistencies in the SCTE-35 message (e.g. mis-match between declared SpliceCommand length and parsed length), but the message on the whole is still parsable, and so instead of killing the whole parse by throwing, the error is just logged to the nonFatalErrors instead.

There is also an initialiser provided for hex encoded strings init(hexString: String) throws, as exampled below.

let hexString = "0xFC3034000000000000FFFFF00506FE72BD0050001E021C435545494800008E7FCF0001A599B00808000000002CA0A18A3402009AC9D17E"
let spliceInfoSection = try SpliceInfoSection(hexString: hexString)

And a convenience init(_ string: String) throws is also provided that makes a best effort to determine whether the message is in a base64 or hex encoded format before attempting to parse the message. The check will determine if the string "looks hex" by checking that it has a 0x prefix, and assuming that attempt to convert to Data using hex format first and failing that trying with Data.init?(base64Encoded base64String: String) (and vice-versa where the string does not "look hex"). This approach is exampled below.

let base64String = "/DA0AAAAAAAA///wBQb+cr0AUAAeAhxDVUVJSAAAjn/PAAGlmbAICAAAAAAsoKGKNAIAmsnRfg=="
let hexString = "0xFC3034000000000000FFFFF00506FE72BD0050001E021C435545494800008E7FCF0001A599B00808000000002CA0A18A3402009AC9D17E"
let spliceInfoSectionFromBase64 = try SpliceInfoSection(base64String)
let spliceInfoSectionFromHex = try SpliceInfoSection(hexString)
XCTAssertEqual(spliceInfoSectionFromBase64, spliceInfoSectionFromHex)

There is also an init(data: Data) throws provided for cases where the input is already converted to Data.

let base64String = "/DA0AAAAAAAA///wBQb+cr0AUAAeAhxDVUVJSAAAjn/PAAGlmbAICAAAAAAsoKGKNAIAmsnRfg=="
let data = Data(base64Encoded: base64String)!
let spliceInfoSection = try SpliceInfoSection(data: data)


Stars: 0
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

3 weeks ago

Add MIT licence.

Some organisations require 3rd party projects to include a licence in order to be used and so I've added a permissive MIT licence to the project.

PR here: https://github.com/theRealRobG/SCTE35Parser/pull/7

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API