MCPcopy Create free account
hub / github.com/0xsequence/czip / WriteSequenceChainedSignature

Method WriteSequenceChainedSignature

compressor/encode.go:808–850  ·  view source on GitHub ↗
(signature []byte)

Source from the content-addressed store, hash-verified

806}
807
808func (buf *Buffer) WriteSequenceChainedSignature(signature []byte) (EncodeType, error) {
809 // First we need to count how many chained signatures are there
810 // for this we read the first 3 bytes of each, as they contain the size
811 var pointer uint
812 var parts [][]byte
813
814 for pointer < uint(len(signature)) {
815 length := uint(signature[pointer])<<16 | uint(signature[pointer+1])<<8 | uint(signature[pointer+2])
816 pointer += 3
817
818 npointer := pointer + length
819 parts = append(parts, signature[pointer:npointer])
820 pointer = npointer
821 }
822
823 // We have two instructions for this, one for 8 bits and one for 16 bits
824 // depending on the number of parts
825 totalParts := uint(len(parts))
826 if totalParts > 255 {
827 buf.commitUint(FLAG_SEQUENCE_READ_CHAINED_L)
828 buf.commitByte(byte(totalParts >> 8))
829 buf.commitByte(byte(totalParts))
830 } else {
831 buf.commitUint(FLAG_SEQUENCE_READ_CHAINED_S)
832 buf.commitByte(byte(totalParts))
833 }
834
835 buf.end([]byte{}, Stateless)
836
837 // Now we need to encode every nested part, one for each signature part
838 encodeType := Stateless
839
840 for _, part := range parts {
841 t, err := buf.WriteSequenceSignature(part, false)
842 if err != nil {
843 return Stateless, err
844 }
845
846 encodeType = maxPriority(encodeType, t)
847 }
848
849 return encodeType, nil
850}
851
852// Encode N bytes, as optimized as possible
853func (buf *Buffer) WriteBytesOptimized(bytes []byte, saveWord bool) (EncodeType, error) {

Callers 2

extras.goFile · 0.80

Calls 5

commitUintMethod · 0.95
commitByteMethod · 0.95
endMethod · 0.95
maxPriorityFunction · 0.85

Tested by

no test coverage detected