Rework writer deadline handling.
[stompngo.git] / utils_exp.go
blob911de9b96b15303420cd0367c89010b35acbef74
1 //
2 // Copyright © 2011-2017 Guy M. Allard
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 package stompngo
19 import (
20 "crypto/rand"
21 "crypto/sha1"
22 "encoding/hex"
23 "fmt"
24 "io"
26 "github.com/gmallard/stompngo/senv"
30 HexData returns a dump formatted value of a byte slice.
32 func HexData(b []uint8) string {
33 td := b[:]
34 m := senv.MaxBodyLength()
35 if m > 0 {
36 if m < len(td) {
37 td = td[:m]
40 return "\n" + hex.Dump(td)
44 Sha1 returns a SHA1 hash for a specified string.
46 func Sha1(q string) string {
47 g := sha1.New()
48 g.Write([]byte(q))
49 return fmt.Sprintf("%x", g.Sum(nil))
53 Uuid returns a type 4 UUID.
55 func Uuid() string {
56 b := make([]byte, 16)
57 _, _ = io.ReadFull(rand.Reader, b)
58 b[6] = (b[6] & 0x0F) | 0x40
59 b[8] = (b[8] &^ 0x40) | 0x80
60 return fmt.Sprintf("%x-%x-%x-%x-%x", b[:4], b[4:6], b[6:8], b[8:10], b[10:])
64 Supported checks if a particular STOMP version is supported in the current
65 implementation.
67 func Supported(v string) bool {
68 return hasValue(supported, v)
72 Protocols returns a slice of client supported protocol levels.
74 func Protocols() []string {
75 return supported