MCPcopy Index your code
hub / github.com/LagrangeDev/LagrangeGo / WritePacketBytes

Method WritePacketBytes

utils/binary/builder.go:81–104  ·  view source on GitHub ↗

WritePacketBytes prefix must not be empty

(v []byte, prefix string, withPrefix bool)

Source from the content-addressed store, hash-verified

79
80// WritePacketBytes prefix must not be empty
81func (b *Builder) WritePacketBytes(v []byte, prefix string, withPrefix bool) *Builder {
82 n := len(v)
83 if withPrefix {
84 plus, err := strconv.Atoi(prefix[1:])
85 if err != nil {
86 panic(err)
87 }
88 n += plus / 8
89 }
90 switch prefix {
91 case "u8":
92 b.WriteU8(uint8(n))
93 case "u16":
94 b.WriteU16(uint16(n))
95 case "u32":
96 b.WriteU32(uint32(n))
97 case "u64":
98 b.WriteU64(uint64(n))
99 default:
100 panic("invaild prefix")
101 }
102 b.WriteBytes(v)
103 return b
104}
105
106func (b *Builder) WritePacketString(s, prefix string, withPrefix bool) *Builder {
107 return b.WritePacketBytes(utils.S2B(s), prefix, withPrefix)

Callers 6

WritePacketStringMethod · 0.95
GetQRCodeResultMethod · 0.80
PackPacketMethod · 0.80
T106Function · 0.80
T128Function · 0.80
T141Function · 0.80

Calls 5

WriteU8Method · 0.95
WriteU16Method · 0.95
WriteU32Method · 0.95
WriteU64Method · 0.95
WriteBytesMethod · 0.95

Tested by

no test coverage detected