Files
consensus/codec/codec.go
T
zeekay ace766cace fix: resolve critical linting issues
- Fix SA4031 nil check error in engine/pq/consensus.go by replacing unreachable nil check with proper certificate validation
- Fix SA9003 empty branch error in engine/pq/engine_test.go by adding meaningful log statement
- Fix integer overflow G115 in quasar.go by avoiding conversion of addition result
- Separate deprecated GetSubnetID export to avoid SA1019 in main exports
- Format all Go files with gofmt
- All tests still passing with 100% success rate
2025-08-23 13:19:08 -05:00

36 lines
856 B
Go

// Package codec provides encoding/decoding for consensus types
package codec
import (
"encoding/json"
"fmt"
)
// CodecVersion represents the codec version
type CodecVersion uint16
const (
// CurrentVersion is the current codec version
CurrentVersion CodecVersion = 0
)
// Codec provides marshaling/unmarshaling
var Codec = &JSONCodec{}
// JSONCodec implements JSON encoding/decoding
type JSONCodec struct{}
// Marshal marshals an object to bytes
func (c *JSONCodec) Marshal(version CodecVersion, v interface{}) ([]byte, error) {
if version != CurrentVersion {
return nil, fmt.Errorf("unsupported codec version: %d", version)
}
return json.Marshal(v)
}
// Unmarshal unmarshals bytes to an object
func (c *JSONCodec) Unmarshal(data []byte, v interface{}) (CodecVersion, error) {
err := json.Unmarshal(data, v)
return CurrentVersion, err
}