Files
zapdb/pb/marshal_zap.go
zeekay 880244d2b7 fix: use native binary encoding for wire-format compatibility with luxfi/badger
Replace proto.Marshal/Unmarshal with native pb.Marshal/pb.Unmarshal to
match the wire format used by luxfi/badger/v4. This ensures databases
written by nodes using the badger fork (v1.23.4) can be read by nodes
using zapdb (v1.23.5), preventing "proto: cannot parse invalid
wire-format data" errors during rolling upgrades.

Added types_zap.go and marshal_zap.go from luxfi/badger fork, which
provide custom LittleEndian binary encoding for ManifestChangeSet,
KV, Checksum, and other internal types. The standard protobuf
generated code (badgerpb4.pb.go) is now behind a grpc build tag.
2026-02-08 18:33:39 -08:00

51 lines
1.2 KiB
Go

//go:build !grpc
/*
* SPDX-FileCopyrightText: 2017-2025 Istari Digital, Inc.
* SPDX-License-Identifier: Apache-2.0
*/
package pb
// Marshaler is the interface for types that can marshal themselves.
type Marshaler interface {
Marshal() ([]byte, error)
}
// Unmarshaler is the interface for types that can unmarshal themselves.
type Unmarshaler interface {
Unmarshal([]byte) error
}
// Sizer is the interface for types that can report their encoded size.
type Sizer interface {
Size() int
}
// Marshal marshals a Marshaler to bytes.
func Marshal(m Marshaler) ([]byte, error) {
return m.Marshal()
}
// Unmarshal unmarshals bytes into an Unmarshaler.
func Unmarshal(data []byte, m Unmarshaler) error {
return m.Unmarshal(data)
}
// Size returns the encoded size of a Sizer.
func Size(m Sizer) int {
return m.Size()
}
// MarshalOptions provides options for marshaling (compatibility with protobuf API).
type MarshalOptions struct{}
// MarshalAppend appends the marshaled form to the provided buffer.
func (MarshalOptions) MarshalAppend(b []byte, m Marshaler) ([]byte, error) {
data, err := m.Marshal()
if err != nil {
return nil, err
}
return append(b, data...), nil
}