Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .license_header_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@@===----------------------------------------------------------------------===@@
@@
@@ This source file is part of the swift-libp2p open source project
@@
@@ Copyright (c) YEARS swift-libp2p project authors
@@ Licensed under MIT
@@
@@ See LICENSE for license information
@@ See CONTRIBUTORS for the list of swift-libp2p project authors
@@
@@ SPDX-License-Identifier: MIT
@@
@@===----------------------------------------------------------------------===@@
11 changes: 11 additions & 0 deletions .licenseignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.github/workflows/configs/.flake8
**/*.yml
*.md
*.txt
Package.swift
Package.resolved
.gitignore
.swift-format
.licenseignore
.license_header_template
Sources/Multicodec/Codecs.swift
68 changes: 68 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"version" : 1,
"indentation" : {
"spaces" : 4
},
"tabWidth" : 4,
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"spacesAroundRangeFormationOperators" : false,
"indentConditionalCompilationBlocks" : false,
"indentSwitchCaseLabels" : false,
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : true,
"lineBreakBeforeEachGenericRequirement" : true,
"lineLength" : 120,
"maximumBlankLines" : 1,
"respectsExistingLineBreaks" : true,
"prioritizeKeepingFunctionOutputTogether" : true,
"noAssignmentInExpressions" : {
"allowedFunctions" : [
"XCTAssertNoThrow",
"XCTAssertThrowsError"
]
},
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : false,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"UseEarlyExits" : false,
"UseExplicitNilCheckInConditions" : false,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : false,
"UseSynthesizedInitializer" : false,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
}
}
37 changes: 26 additions & 11 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,42 +1,57 @@
// swift-tools-version:5.4
// The swift-tools-version declares the minimum version of Swift required to build this package.
// swift-tools-version:5.5
//===----------------------------------------------------------------------===//
//
// This source file is part of the swift-libp2p open source project
//
// Copyright (c) 2022-2025 swift-libp2p project authors
// Licensed under MIT
//
// See LICENSE for license information
// See CONTRIBUTORS for the list of swift-libp2p project authors
//
// SPDX-License-Identifier: MIT
//
//===----------------------------------------------------------------------===//

import PackageDescription

let package = Package(
name: "swift-multicodec",
platforms: [
.macOS(.v10_10),
.iOS(.v10)
.iOS(.v10),
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.executable(
name: "update-codecs",
targets: ["Updater"]),
targets: ["Updater"]
),
.library(
name: "Multicodec",
targets: ["Multicodec"]),
targets: ["Multicodec"]
),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
//.package(name: "VarInt", path: "../VarInt") //Use this when attempting to run update-codecs (until our repo is public)
.package(url: "https://github.com/swift-libp2p/swift-varint.git", from: "0.0.1")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.executableTarget(
name: "Updater",
dependencies: []),
dependencies: []
),
.target(
name: "Multicodec",
dependencies: [
.product(name: "VarInt", package: "swift-varint"),
]),
.product(name: "VarInt", package: "swift-varint")
]
),
.testTarget(
name: "MulticodecTests",
dependencies: ["Multicodec"]),
dependencies: ["Multicodec"]
),
]
)
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ let package = Package(
)
```


## Usage

### Example

```Swift
```swift

import Multicodec

Expand Down Expand Up @@ -72,7 +71,7 @@ Updating the Codec enum is done by running the following command at the projects

## Contributing

Contributions are welcomed! This code is very much a proof of concept. I can guarantee you there's a better / safer way to accomplish the same results. Any suggestions, improvements, or even just critques, are welcome!
Contributions are welcomed! This code is very much a proof of concept. I can guarantee you there's a better / safer way to accomplish the same results. Any suggestions, improvements, or even just critiques, are welcome!

Let's make this code better together! 🤝

Expand Down
38 changes: 22 additions & 16 deletions Sources/Multicodec/Codecs+Equatable.swift
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Codecs+Equatable.swift
//
// This source file is part of the swift-libp2p open source project
//
// Created by Brandon Toms on 5/1/22.
// Copyright (c) 2022-2025 swift-libp2p project authors
// Licensed under MIT
//
// See LICENSE for license information
// See CONTRIBUTORS for the list of swift-libp2p project authors
//
// SPDX-License-Identifier: MIT
//
//===----------------------------------------------------------------------===//

import Foundation

public extension Codecs {
static func ==(lhs: Codecs, rhs: Codecs) -> Bool {
return lhs.rawValue == rhs.rawValue
extension Codecs {
public static func == (lhs: Codecs, rhs: Codecs) -> Bool {
lhs.rawValue == rhs.rawValue
}
static func ==(lhs: Codecs, rhs: Int64) -> Bool {
return lhs.rawValue == rhs

public static func == (lhs: Codecs, rhs: Int64) -> Bool {
lhs.rawValue == rhs
}

static func ==(lhs: Codecs, rhs: Int) -> Bool {
return lhs.rawValue == Int64(rhs)
public static func == (lhs: Codecs, rhs: Int) -> Bool {
lhs.rawValue == Int64(rhs)
}

static func ==(lhs: Codecs, rhs: String) -> Bool {
return lhs.name == rhs
public static func == (lhs: Codecs, rhs: String) -> Bool {
lhs.name == rhs
}
func isEqual(object: AnyObject?) -> Bool {

public func isEqual(object: AnyObject?) -> Bool {
if let obj = object as? Codecs {
return self.rawValue == obj.rawValue
} else if let obj = object as? Int64 {
Expand Down Expand Up @@ -57,4 +64,3 @@ public extension Codecs {
// return lhs.rawValue == rhs
// }
//}

Loading
Loading