github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/protocol/syllab.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package protocol 4 5 const ( 6 SyllabDomain = "syllab.protocol" 7 8 SyllabServiceCompleteGoSyllabMethods = "urn:giti:syllab.protocol:service:complete-go-syllab-methods" 9 SyllabServiceGenerateGoSyllabMethods = "urn:giti:syllab.protocol:service:generate-go-syllab-methods" 10 ) 11 12 // Syllab is the interface that must implement by any struct to be a Syllab object tranmitable over networks! 13 // Standards in https://github.com/GeniusesGroup/RFCs/blob/master/Syllab.md 14 type Syllab interface { 15 // CheckSyllab usually just check LenOfSyllabStack not greater than len of given payload. and call just before decode payload. 16 CheckSyllab(payload []byte) (err Error) 17 18 // ToSyllab encode the struct pointer to Syllab format 19 // in non embed struct usually `stackIndex = 0` & `heapIndex = {{rn}}.LenOfSyllabStack()` as heap start index || end of stack size! 20 ToSyllab(payload []byte, stackIndex, heapIndex uint32) (freeHeapIndex uint32) 21 // FromSyllab decode Syllab to the struct pointer! 22 FromSyllab(payload []byte, stackIndex uint32) 23 24 // LenAsSyllab return whole calculated length of Syllab encoded of the struct 25 // default is simple as `return uint64({{RecName}}.LenOfSyllabStack() + {{RecName}}.LenOfSyllabHeap())` 26 LenAsSyllab() uint64 27 28 // LenOfSyllabStack return calculated stack length of Syllab encoded of the struct 29 LenOfSyllabStack() uint32 30 // LenOfSyllabStack return calculated heap length of Syllab encoded of the struct 31 LenOfSyllabHeap() uint32 32 }