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

New Feature Request: Add protobuf struct tags #59

Open
seb06cai opened this issue Oct 4, 2022 · 1 comment
Open

New Feature Request: Add protobuf struct tags #59

seb06cai opened this issue Oct 4, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@seb06cai
Copy link

seb06cai commented Oct 4, 2022

Currently, it is not possible to use the official CDX protobuf schema to serialize json and/or xml bom files. In order to serialize the files, the CDX golang library works well, but we still need to serialize the golang Bom struct into a protobuf message in order to transmit the data between services.

Protobuf struct tags should allow this to work, where a CDX bom file is first serialized using the golang library, and then serialized into the official CDX protobuf schema using the protobuf struct tags.

@nscuro
Copy link
Member

nscuro commented Oct 6, 2022

So I looked into this, and it turns out it indeed can not be solved by simply adding struct tags.

Even if Protobuf supports struct tags in the way we'd need it here, the existing structs won't cleanly map to the Protobuf schema.

I think what we need to do instead is generating code from the official schema, and then provide functions to support mapping from and to the different models. That could end up looking like this in practice:

import (
    "google.golang.org/protobuf/proto"

    cdx "github.com/CycloneDX/cyclonedx-go"
    cdxproto "github.com/CycloneDX/cyclonedx-go/proto"
)

func Foo() {
    bom := cdx.BOM{
        // ...
    }
    bytes, err := proto.Marshal(bom.ToProto())

    bomProto := cdxproto.Bom{}
    err = proto.Unmarshal(bytes, &bomProto)
    bom.FromProto(bomProto)
}

While it's not pretty, I think it's acceptable. Means we'll have to do lots of manual mapping though. 🫠

@nscuro nscuro added the enhancement New feature or request label Aug 3, 2023
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

2 participants