[#77] protogen: Initial implementation
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
a28ceb251a
commit
0eb4583930
115 changed files with 36376 additions and 20397 deletions
|
@ -17,6 +17,10 @@ import (
|
|||
type (
|
||||
stableMarshaler interface {
|
||||
StableMarshal([]byte) []byte
|
||||
stableSizer
|
||||
}
|
||||
|
||||
stableSizer interface {
|
||||
StableSize() int
|
||||
}
|
||||
|
||||
|
@ -277,6 +281,11 @@ type ptrStableMarshaler[T any] interface {
|
|||
~*T
|
||||
}
|
||||
|
||||
type ptrStableSizer[T any] interface {
|
||||
stableSizer
|
||||
~*T
|
||||
}
|
||||
|
||||
func NestedStructureMarshal[T any, M ptrStableMarshaler[T]](field int64, buf []byte, v M) int {
|
||||
if v == nil {
|
||||
return 0
|
||||
|
@ -320,7 +329,7 @@ func NestedStructureSetMarshalData[T any, M setMarshalData[T]](field int64, pare
|
|||
return offset + n
|
||||
}
|
||||
|
||||
func NestedStructureSize[T any, M ptrStableMarshaler[T]](field int64, v M) (size int) {
|
||||
func NestedStructureSize[T any, M ptrStableSizer[T]](field int64, v M) (size int) {
|
||||
if v == nil {
|
||||
return 0
|
||||
}
|
||||
|
@ -328,7 +337,7 @@ func NestedStructureSize[T any, M ptrStableMarshaler[T]](field int64, v M) (size
|
|||
return NestedStructureSizeUnchecked(field, v)
|
||||
}
|
||||
|
||||
func NestedStructureSizeUnchecked[T stableMarshaler](field int64, v T) int {
|
||||
func NestedStructureSizeUnchecked[T stableSizer](field int64, v T) int {
|
||||
n := v.StableSize()
|
||||
return protowire.SizeGroup(protowire.Number(field), protowire.SizeBytes(n))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue