Skip to content

Commit 3d2537b

Browse files
authored
codec: remove SetMaxSize from Manager (ava-labs#1481)
1 parent e2b4d9a commit 3d2537b

File tree

2 files changed

+1
-28
lines changed

2 files changed

+1
-28
lines changed

codec/manager.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ type Manager interface {
4040
// Associate the given codec with the given version ID
4141
RegisterCodec(version uint16, codec Codec) error
4242

43-
// Define the maximum size, in bytes, of something serialized/deserialized
44-
// by this codec manager
45-
SetMaxSize(int)
46-
4743
// Size returns the size, in bytes, of [value] when it's marshaled
4844
// using the codec with the given version.
4945
// RegisterCodec must have been called with that version.
@@ -92,13 +88,6 @@ func (m *manager) RegisterCodec(version uint16, codec Codec) error {
9288
return nil
9389
}
9490

95-
// SetMaxSize of bytes allowed
96-
func (m *manager) SetMaxSize(size int) {
97-
m.lock.Lock()
98-
m.maxSize = size
99-
m.lock.Unlock()
100-
}
101-
10291
func (m *manager) Size(version uint16, value interface{}) (int, error) {
10392
if value == nil {
10493
return 0, errMarshalNil // can't marshal nil
@@ -127,7 +116,6 @@ func (m *manager) Marshal(version uint16, value interface{}) ([]byte, error) {
127116
m.lock.RLock()
128117
c, exists := m.codecs[version]
129118
m.lock.RUnlock()
130-
131119
if !exists {
132120
return nil, ErrUnknownVersion
133121
}
@@ -150,22 +138,19 @@ func (m *manager) Unmarshal(bytes []byte, dest interface{}) (uint16, error) {
150138
return 0, errUnmarshalNil
151139
}
152140

153-
m.lock.RLock()
154141
if byteLen := len(bytes); byteLen > m.maxSize {
155-
m.lock.RUnlock()
156142
return 0, fmt.Errorf("%w: %d > %d", errUnmarshalTooBig, byteLen, m.maxSize)
157143
}
158144

159145
p := wrappers.Packer{
160146
Bytes: bytes,
161147
}
162-
163148
version := p.UnpackShort()
164149
if p.Errored() { // Make sure the codec version is correct
165-
m.lock.RUnlock()
166150
return 0, errCantUnpackVersion
167151
}
168152

153+
m.lock.RLock()
169154
c, exists := m.codecs[version]
170155
m.lock.RUnlock()
171156
if !exists {

codec/mock_manager.go

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)