diff --git a/pkg/vss/convert/errors.go b/pkg/vss/convert/errors.go index fbcb557..22de845 100644 --- a/pkg/vss/convert/errors.go +++ b/pkg/vss/convert/errors.go @@ -9,7 +9,7 @@ type VersionError struct { // Error returns the error message. func (e VersionError) Error() string { - return fmt.Sprintf("unsupported specversion: %s", e.Version) + return fmt.Sprintf("unsupported verision: %s", e.Version) } // FieldNotFoundError is an error for missing fields. diff --git a/pkg/vss/convert/payloadv1.go b/pkg/vss/convert/payloadv1.go index f241428..e6ab0ad 100644 --- a/pkg/vss/convert/payloadv1.go +++ b/pkg/vss/convert/payloadv1.go @@ -18,11 +18,11 @@ type TokenIDGetter interface { // SignalsFromV1Payload gets a slice signals from a v1 payload. func SignalsFromV1Payload(ctx context.Context, tokenGetter TokenIDGetter, jsonData []byte) ([]vss.Signal, error) { - ts, err := timestampFromV1Data(jsonData) + ts, err := TimestampFromV1Data(jsonData) if err != nil { return nil, fmt.Errorf("error getting timestamp: %w", err) } - sub, err := subjectFromV1Data(jsonData) + sub, err := SubjectFromV1Data(jsonData) if err != nil { return nil, fmt.Errorf("error getting subject: %w", err) } @@ -31,7 +31,7 @@ func SignalsFromV1Payload(ctx context.Context, tokenGetter TokenIDGetter, jsonDa return nil, fmt.Errorf("error getting tokenID from subject: %w", err) } - source, err := sourceFromV1Data(jsonData) + source, err := SourceFromV1Data(jsonData) baseSignal := vss.Signal{ TokenID: tokenID, Timestamp: ts, @@ -44,7 +44,8 @@ func SignalsFromV1Payload(ctx context.Context, tokenGetter TokenIDGetter, jsonDa return sigs, nil } -func subjectFromV1Data(jsonData []byte) (string, error) { +// SubjectFromV1Data gets a subject from a v1 payload. +func SubjectFromV1Data(jsonData []byte) (string, error) { result := gjson.GetBytes(jsonData, "subject") if !result.Exists() { return "", FieldNotFoundError{Field: "subject", Lookup: "subject"} @@ -56,7 +57,8 @@ func subjectFromV1Data(jsonData []byte) (string, error) { return sub, nil } -func timestampFromV1Data(jsonData []byte) (time.Time, error) { +// TimestampFromV1Data gets a timestamp from a v1 payload. +func TimestampFromV1Data(jsonData []byte) (time.Time, error) { result := gjson.GetBytes(jsonData, "time") if !result.Exists() { return time.Time{}, FieldNotFoundError{Field: "timestamp", Lookup: "time"} @@ -77,7 +79,8 @@ func timestampFromV1Data(jsonData []byte) (time.Time, error) { return ts, nil } -func sourceFromV1Data(jsonData []byte) (string, error) { +// SourceFromV1Data gets a source field from a v1 payload. +func SourceFromV1Data(jsonData []byte) (string, error) { result := gjson.GetBytes(jsonData, "source") if !result.Exists() { return "", FieldNotFoundError{Field: "source", Lookup: "source"} diff --git a/pkg/vss/convert/payloadv2.go b/pkg/vss/convert/payloadv2.go index ee0cd79..0c78238 100644 --- a/pkg/vss/convert/payloadv2.go +++ b/pkg/vss/convert/payloadv2.go @@ -21,11 +21,11 @@ func SignalsFromV2Payload(jsonData []byte) ([]vss.Signal, error) { if !signals.IsArray() { return nil, errors.New("signals field is not an array") } - tokenID, err := tokenIDFromV2Data(jsonData) + tokenID, err := TokenIDFromV2Data(jsonData) if err != nil { return nil, fmt.Errorf("error getting tokenID: %w", err) } - source, err := sourceFromV2Data(jsonData) + source, err := SourceFromV2Data(jsonData) if err != nil { return nil, fmt.Errorf("error getting source: %w", err) } @@ -35,12 +35,12 @@ func SignalsFromV2Payload(jsonData []byte) ([]vss.Signal, error) { Source: source, } for _, sigData := range signals.Array() { - originalName, err := signalNameFromV2Data(sigData) + originalName, err := NameFromV2Signal(sigData) if err != nil { errs = errors.Join(errs, err) continue } - ts, err := timestampFromV2Data(sigData) + ts, err := TimestampFromV2Signal(sigData) if err != nil { err = fmt.Errorf("error for '%s': %w", originalName, err) errs = errors.Join(errs, err) @@ -57,7 +57,8 @@ func SignalsFromV2Payload(jsonData []byte) ([]vss.Signal, error) { return retSignals, errs } -func tokenIDFromV2Data(jsonData []byte) (uint32, error) { +// TokenIDFromV2Data gets a tokenID from a V2 payload. +func TokenIDFromV2Data(jsonData []byte) (uint32, error) { lookupKey := "vehicleTokenId" tokenID := gjson.GetBytes(jsonData, lookupKey) if !tokenID.Exists() { @@ -70,7 +71,8 @@ func tokenIDFromV2Data(jsonData []byte) (uint32, error) { return float64toUint32(id), nil } -func timestampFromV2Data(sigResult gjson.Result) (time.Time, error) { +// TimestampFromV2Signal gets a timestamp from a V2 signal. +func TimestampFromV2Signal(sigResult gjson.Result) (time.Time, error) { lookupKey := "timestamp" timestamp := sigResult.Get(lookupKey) if !timestamp.Exists() { @@ -79,7 +81,8 @@ func timestampFromV2Data(sigResult gjson.Result) (time.Time, error) { return time.UnixMilli(int64(timestamp.Uint())).UTC(), nil } -func signalNameFromV2Data(sigResult gjson.Result) (string, error) { +// NameFromV2Signal gets a name from a V2 signal. +func NameFromV2Signal(sigResult gjson.Result) (string, error) { lookupKey := "name" signalName := sigResult.Get(lookupKey) if !signalName.Exists() { @@ -88,7 +91,8 @@ func signalNameFromV2Data(sigResult gjson.Result) (string, error) { return signalName.String(), nil } -func sourceFromV2Data(jsonData []byte) (string, error) { +// SourceFromV2Data gets a source from a V2 payload. +func SourceFromV2Data(jsonData []byte) (string, error) { lookupKey := "source" source := gjson.GetBytes(jsonData, lookupKey) if !source.Exists() {