MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / EncodeWaveOSCBytes

Function EncodeWaveOSCBytes

pkg/wshutil/wshutil.go:74–113  ·  view source on GitHub ↗
(oscNum string, barr []byte)

Source from the content-addressed store, hash-verified

72}
73
74func EncodeWaveOSCBytes(oscNum string, barr []byte) ([]byte, error) {
75 if len(oscNum) != 5 {
76 return nil, fmt.Errorf("oscNum must be 5 characters")
77 }
78 const maxSize = 64 * 1024 * 1024 // 64 MB
79 if len(barr) > maxSize {
80 return nil, fmt.Errorf("input data too large")
81 }
82 hasControlChars := false
83 for _, b := range barr {
84 if b < 0x20 || b == 0x7F {
85 hasControlChars = true
86 break
87 }
88 }
89 if !hasControlChars {
90 // If no control characters, directly construct the output
91 // \x1b] (2) + WaveOSC + ; (1) + message + \x07 (1)
92 output := make([]byte, oscPrefixLen(oscNum)+len(barr)+1)
93 copyOscPrefix(output, oscNum)
94 copy(output[oscPrefixLen(oscNum):], barr)
95 output[len(output)-1] = BEL
96 return output, nil
97 }
98
99 var buf bytes.Buffer
100 buf.Write(makeOscPrefix(oscNum))
101 escSeq := [6]byte{'\\', 'u', '0', '0', '0', '0'}
102 for _, b := range barr {
103 if b < 0x20 || b == 0x7f {
104 escSeq[4] = HexChars[b>>4]
105 escSeq[5] = HexChars[b&0x0f]
106 buf.Write(escSeq[:])
107 } else {
108 buf.WriteByte(b)
109 }
110 }
111 buf.WriteByte(BEL)
112 return buf.Bytes(), nil
113}
114
115func EncodeWaveOSCMessageEx(oscNum string, msg *RpcMessage) ([]byte, error) {
116 if msg == nil {

Callers 2

EncodeWaveOSCMessageExFunction · 0.85
AdaptMsgChToPtyFunction · 0.85

Calls 5

oscPrefixLenFunction · 0.85
copyOscPrefixFunction · 0.85
makeOscPrefixFunction · 0.85
BytesMethod · 0.80
WriteMethod · 0.65

Tested by

no test coverage detected