From 437415ca92a98783d03e71c689bdbb58fe0a8d51 Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Mon, 30 Jun 2025 13:31:56 -0700 Subject: Add type safety to field system with FieldType alias - Define FieldType as typed alias for [2]byte to improve type safety - Update all 47 field constants to use FieldType instead of raw [2]byte - Update Field struct to use FieldType for Type field - Update function signatures: NewField, GetField, Transaction.GetField - Fix field_test.go to use new FieldType in test cases - Maintains backward compatibility with zero runtime overhead - Enhances API clarity and prevents accidental field type misuse --- hotline/field_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'hotline/field_test.go') diff --git a/hotline/field_test.go b/hotline/field_test.go index 213d9c3..676098c 100644 --- a/hotline/field_test.go +++ b/hotline/field_test.go @@ -102,7 +102,7 @@ func Test_fieldScanner(t *testing.T) { func TestField_Read(t *testing.T) { type fields struct { - ID [2]byte + Type FieldType FieldSize [2]byte Data []byte readOffset int @@ -121,7 +121,7 @@ func TestField_Read(t *testing.T) { { name: "returns field bytes", fields: fields{ - ID: [2]byte{0x00, 0x62}, + Type: FieldType{0x00, 0x62}, FieldSize: [2]byte{0x00, 0x03}, Data: []byte("hai!"), }, @@ -139,7 +139,7 @@ func TestField_Read(t *testing.T) { { name: "returns field bytes from readOffset", fields: fields{ - ID: [2]byte{0x00, 0x62}, + Type: FieldType{0x00, 0x62}, FieldSize: [2]byte{0x00, 0x03}, Data: []byte("hai!"), readOffset: 4, @@ -156,7 +156,7 @@ func TestField_Read(t *testing.T) { { name: "returns io.EOF when all bytes read", fields: fields{ - ID: [2]byte{0x00, 0x62}, + Type: FieldType{0x00, 0x62}, FieldSize: [2]byte{0x00, 0x03}, Data: []byte("hai!"), readOffset: 8, @@ -172,7 +172,7 @@ func TestField_Read(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { f := &Field{ - Type: tt.fields.ID, + Type: tt.fields.Type, FieldSize: tt.fields.FieldSize, Data: tt.fields.Data, readOffset: tt.fields.readOffset, -- cgit