Skip to content

Commit 336de9d

Browse files
authored
Merge pull request #395 from blinklabs-io/feat/cbor-consistent-naming
feat: consistent naming for CBOR constants
2 parents 5a96a5d + 9adc14e commit 336de9d

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

cbor/cbor.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ import (
1919
)
2020

2121
const (
22-
CBOR_TYPE_BYTE_STRING uint8 = 0x40
23-
CBOR_TYPE_TEXT_STRING uint8 = 0x60
24-
CBOR_TYPE_ARRAY uint8 = 0x80
25-
CBOR_TYPE_MAP uint8 = 0xa0
26-
CBOR_TYPE_TAG uint8 = 0xc0
22+
CborTypeByteString uint8 = 0x40
23+
CborTypeTextString uint8 = 0x60
24+
CborTypeArray uint8 = 0x80
25+
CborTypeMap uint8 = 0xa0
26+
CborTypeTag uint8 = 0xc0
2727

2828
// Only the top 3 bytes are used to specify the type
29-
CBOR_TYPE_MASK uint8 = 0xe0
29+
CborTypeMask uint8 = 0xe0
3030

3131
// Max value able to be stored in a single byte without type prefix
32-
CBOR_MAX_UINT_SIMPLE uint8 = 0x17
32+
CborMaxUintSimple uint8 = 0x17
3333

3434
// Useful tag numbers
3535
CborTagCbor = 24

cbor/decode.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ func DecodeIdFromList(cborData []byte) (int, error) {
5353
if listLen == 0 {
5454
return 0, fmt.Errorf("cannot return first item from empty list")
5555
}
56-
if listLen < int(CBOR_MAX_UINT_SIMPLE) {
57-
if cborData[1] <= CBOR_MAX_UINT_SIMPLE {
56+
if listLen < int(CborMaxUintSimple) {
57+
if cborData[1] <= CborMaxUintSimple {
5858
return int(cborData[1]), nil
5959
}
6060
}
@@ -77,8 +77,8 @@ func DecodeIdFromList(cborData []byte) (int, error) {
7777
func ListLength(cborData []byte) (int, error) {
7878
// If the list length is <= the max simple uint, then we can extract the length
7979
// value straight from the byte slice (with a little math)
80-
if cborData[0] >= CBOR_TYPE_ARRAY && cborData[0] <= (CBOR_TYPE_ARRAY+CBOR_MAX_UINT_SIMPLE) {
81-
return int(cborData[0]) - int(CBOR_TYPE_ARRAY), nil
80+
if cborData[0] >= CborTypeArray && cborData[0] <= (CborTypeArray+CborMaxUintSimple) {
81+
return int(cborData[0]) - int(CborTypeArray), nil
8282
}
8383
// If we couldn't use the shortcut above, actually decode the list
8484
var tmp []RawMessage

cbor/value.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,26 @@ type Value struct {
3434
func (v *Value) UnmarshalCBOR(data []byte) error {
3535
// Save the original CBOR
3636
v.cborData = string(data[:])
37-
cborType := data[0] & CBOR_TYPE_MASK
37+
cborType := data[0] & CborTypeMask
3838
switch cborType {
39-
case CBOR_TYPE_MAP:
39+
case CborTypeMap:
4040
return v.processMap(data)
41-
case CBOR_TYPE_ARRAY:
41+
case CborTypeArray:
4242
return v.processArray(data)
43-
case CBOR_TYPE_TEXT_STRING:
43+
case CborTypeTextString:
4444
var tmpValue string
4545
if _, err := Decode(data, &tmpValue); err != nil {
4646
return err
4747
}
4848
v.value = tmpValue
49-
case CBOR_TYPE_BYTE_STRING:
49+
case CborTypeByteString:
5050
// Use our custom type which stores the bytestring in a way that allows it to be used as a map key
5151
var tmpValue ByteString
5252
if _, err := Decode(data, &tmpValue); err != nil {
5353
return err
5454
}
5555
v.value = tmpValue
56-
case CBOR_TYPE_TAG:
56+
case CborTypeTag:
5757
// Parse as a raw tag to get number and nested CBOR data
5858
tmpTag := RawTag{}
5959
if _, err := Decode(data, &tmpTag); err != nil {

0 commit comments

Comments
 (0)