File: bytes.go

package info (click to toggle)
golang-github-twstrike-otr3 0.0~git20161015.0.744856d-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,008 kB
  • ctags: 1,863
  • sloc: ansic: 127; makefile: 76
file content (35 lines) | stat: -rw-r--r-- 1,083 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package otr3

// MessagePlaintext contains regular plaintext to send or receive
type MessagePlaintext []byte

// A messageWithHeader is simply a full message with all content but not valid to send
type messageWithHeader []byte

// An encoded message have been encoded and is in the final form of an OTR message.
type encodedMessage []byte

// ValidMessage is a message that has gone through fragmentation and is valid to send through the IM client
// Some encodedMessage instances are validMessage instances, but this depends on the fragmentation size
type ValidMessage []byte

// Bytes will turn a slice of valid messages into a slice of byte slices
func Bytes(m []ValidMessage) [][]byte {
	ret := make([][]byte, len(m))
	//copy because we don't want to hold references to m's fragments
	for i, f := range m {
		ret[i] = make([]byte, len(f))
		copy(ret[i], []byte(f))
	}
	return ret
}

func compactMessagesWithHeader(msgs ...messageWithHeader) []messageWithHeader {
	var res []messageWithHeader
	for _, m := range msgs {
		if m != nil {
			res = append(res, m)
		}
	}
	return res
}