Closed DeshErBojhaa closed 2 years ago
PSA: rambling ahead, more of a reflection for the future rather than review
Since length prefix is a generic operation, I wonder if we could refactor this in a separate func that can be used in the future as well in other parsing situations.
Something like:
func LengthPrefixedData(prefixLen int, data []byte) ([]byte, error)
In this instance,
LengthPrefixedData
would be called withprefixLen == 1
, to mark the first byte indata
as the length.
I actually thought the same since the same logic was applied twice in the same function 😛 I didn't want to overthink this but in my head it would look like this (can be extended and improved):
type LengthPrefixedKey []byte
func (k LengthPrefixedKey) Length() int {
return k[0]
}
func (k LengthPrefixedKey) Key() []byte {
return k[1:k.Length()+1]
}
func ExampleUsage() {
b := []byte{ 2, 1, 2 }
k := LengthPrefixedKey(b).Key()
fmt.Println(k)
}
Cool!
I like this a lot, if we could squeeze in variable-len in a endianess-safe way it would be great.
Hi, @Pitasi, @gsora loving this conversation, let's move it to 235
Closes the double value showing after re delegation: https://github.com/allinbits/demeris-backend/issues/366
This PR does not deal with https://app.zenhub.com/workspaces/emeris-back-end-619cd009cc778000112d6259/issues/allinbits/demeris-backend/235. But the solution is very closely related. When we fix 235, we will use the
prefix
that we extract from the delegation key. Right now we just ignore theprefix
.