[#77] protogen: Initial implementation

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-04-25 15:13:10 +03:00
parent a28ceb251a
commit adb7c602d7
115 changed files with 36376 additions and 20397 deletions

View file

@ -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))
}