go-restruct / restruct

Rich binary (de)serialization library for Golang
https://restruct.io/
ISC License
360 stars 17 forks source link

[FEATURE] "remainder" option #52

Open johnnybubonic opened 2 years ago

johnnybubonic commented 2 years ago

Only allowed in the Root, and only once as the last field defined in the struct, a remainder option should be supported to capture any remaining bytes from the source.

This is useful for padding, especially in the case of "sequential padding" (such as what e.g. OpenSSH uses in their private keys, e.g. 0x01 0x02 0x03.... rather than simply padding with null bytes) and other custom padding schemes.

e.g.:

// (...)
FieldName []byte `struct:"remainder"`
// (...)