blob: c7c2120c76501ffa74187d16830d7af75bdeb737 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file implements the simple output formats (binary and base64).
package source_generator
import (
"config"
"encoding/base64"
"google.golang.org/protobuf/proto"
)
// Outputs the serialized proto.
func BinaryOutput(_, filtered *config.CobaltRegistry) (outputBytes []byte, err error) {
return proto.MarshalOptions{
Deterministic: true,
}.Marshal(filtered)
}
// Outputs the serialized proto base64 encoded.
func Base64Output(c, filtered *config.CobaltRegistry) (outputBytes []byte, err error) {
configBytes, err := BinaryOutput(c, filtered)
if err != nil {
return outputBytes, err
}
encoder := base64.StdEncoding
outLen := encoder.EncodedLen(len(configBytes))
outputBytes = make([]byte, outLen, outLen)
encoder.Encode(outputBytes, configBytes)
return outputBytes, nil
}