Skip to content

Commit

Permalink
Replace magic number with constant
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamacker committed Oct 2, 2023
1 parent 90be7ac commit f3fdb2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ const (
inlinedCBORValueIDHeadSize +
inlinedValueIDSize +
arrayDataSlabElementHeadSize

maxInlinedExtraDataIndex = 255
)

type ArraySlabHeader struct {
Expand Down Expand Up @@ -697,9 +699,9 @@ func (a *ArrayDataSlab) encodeAsInlined(enc *Encoder, inlinedTypeInfo *inlinedEx

extraDataIndex := inlinedTypeInfo.addArrayExtraData(a.extraData)

if extraDataIndex > 255 {
if extraDataIndex > maxInlinedExtraDataIndex {
return NewEncodingError(
fmt.Errorf("failed to encode inlined array data slab: extra data index %d exceeds limit 255", extraDataIndex))
fmt.Errorf("failed to encode inlined array data slab: extra data index %d exceeds limit %d", extraDataIndex, maxInlinedExtraDataIndex))
}

var err error
Expand Down
8 changes: 4 additions & 4 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -2820,8 +2820,8 @@ func (m *MapDataSlab) encodeAsInlinedMap(enc *Encoder, inlinedTypeInfo *inlinedE

extraDataIndex := inlinedTypeInfo.addMapExtraData(m.extraData)

if extraDataIndex > 255 {
return NewEncodingError(fmt.Errorf("extra data index %d exceeds limit 255", extraDataIndex))
if extraDataIndex > maxInlinedExtraDataIndex {
return NewEncodingError(fmt.Errorf("extra data index %d exceeds limit %d", extraDataIndex, maxInlinedExtraDataIndex))
}

var err error
Expand Down Expand Up @@ -2885,9 +2885,9 @@ func encodeAsInlinedComposite(
return NewEncodingError(fmt.Errorf("number of elements %d is different from number of elements in cached composite type %d", len(keys), len(cachedKeys)))
}

if extraDataIndex > 255 {
if extraDataIndex > maxInlinedExtraDataIndex {
// This should never happen because of slab size.
return NewEncodingError(fmt.Errorf("extra data index %d exceeds limit 255", extraDataIndex))
return NewEncodingError(fmt.Errorf("extra data index %d exceeds limit %d", extraDataIndex, maxInlinedExtraDataIndex))
}

var err error
Expand Down

0 comments on commit f3fdb2d

Please sign in to comment.