git.gammaspectra.live/P2Pool/consensus/v3@v3.8.0/monero/client/levin/boost.go (about)

     1  package levin
     2  
     3  import (
     4  	"encoding/binary"
     5  	"fmt"
     6  )
     7  
     8  const (
     9  	BoostSerializeTypeInt64 byte = 0x1
    10  	BoostSerializeTypeInt32 byte = 0x2
    11  	BoostSerializeTypeInt16 byte = 0x3
    12  	BoostSerializeTypeInt8  byte = 0x4
    13  
    14  	BoostSerializeTypeUint64 byte = 0x5
    15  	BoostSerializeTypeUint32 byte = 0x6
    16  	BoostSerializeTypeUint16 byte = 0x7
    17  	BoostSerializeTypeUint8  byte = 0x8
    18  
    19  	BoostSerializeTypeDouble byte = 0x9
    20  
    21  	BoostSerializeTypeString byte = 0x0a
    22  	BoostSerializeTypeBool   byte = 0x0b
    23  	BoostSerializeTypeObject byte = 0x0c
    24  	BoostSerializeTypeArray  byte = 0xd
    25  
    26  	BoostSerializeFlagArray byte = 0x80
    27  )
    28  
    29  type BoostByte byte
    30  
    31  func (v BoostByte) Bytes() []byte {
    32  	return []byte{
    33  		BoostSerializeTypeUint8,
    34  		byte(v),
    35  	}
    36  }
    37  
    38  type BoostUint32 uint32
    39  
    40  func (v BoostUint32) Bytes() []byte {
    41  	b := []byte{
    42  		BoostSerializeTypeUint32,
    43  		0x00, 0x00, 0x00, 0x00,
    44  	}
    45  	binary.LittleEndian.PutUint32(b[1:], uint32(v))
    46  	return b
    47  }
    48  
    49  type BoostUint64 uint64
    50  
    51  func (v BoostUint64) Bytes() []byte {
    52  	b := []byte{
    53  		BoostSerializeTypeUint64,
    54  		0x00, 0x00, 0x00, 0x00,
    55  		0x00, 0x00, 0x00, 0x00,
    56  	}
    57  
    58  	binary.LittleEndian.PutUint64(b[1:], uint64(v))
    59  
    60  	return b
    61  }
    62  
    63  type BoostString string
    64  
    65  func (v BoostString) Bytes() []byte {
    66  	b := []byte{BoostSerializeTypeString}
    67  
    68  	varInB, err := VarIn(len(v))
    69  	if err != nil {
    70  		panic(fmt.Errorf("varin '%d': %w", len(v), err))
    71  	}
    72  
    73  	return append(b, append(varInB, []byte(v)...)...)
    74  }