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

Add support for generating Packable conformance using attached macros #1

Open
mattcox opened this issue Apr 10, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@mattcox
Copy link
Owner

mattcox commented Apr 10, 2024

Similar to automatic conformance for Codable, Pack should be able to generate automatic conformance to the Packable protocol using attached macros.

For example, the following type:

struct Color {
    let name: String
    var red: Double
    var green: Double
    var blue: Double
    var alpha: Double = 1.0
}

Should be able to attach a macro such as @packable to the structure, and the implementation would be automatically generated.

@packable
struct Color {
    let name: String
    var red: Double
    var green: Double
    var blue: Double
    var alpha: Double = 1.0

// - - - - - - - - - - - - - - Generated - - - - - - - - - - - - - -
    init(from unpacker: inout Unpacker) throws {
        self.name = try unpacker.unpack(String.self, using: .utf16)
        self.red = try unpacker.unpack(Double.self)
        self.green = try unpacker.unpack(Double.self)
        self.blue = try unpacker.unpack(Double.self)
        self.alpha = try unpacker.unpack(Double.self)
    }

    func pack(to packer: inout Packer) throws {
        try packer.pack(name, using: .utf16)
        try packer.pack(red)
        try packer.pack(green)
        try packer.pack(blue)
        try packer.pack(alpha)
    }
// - - - - - - - - - - - - - - Generated - - - - - - - - - - - - - -
}
@mattcox mattcox added the enhancement New feature or request label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant