-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.go
52 lines (43 loc) · 1.71 KB
/
tag.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*******************************************************************************
* Copyright (c) 2009-2022 Crater Dog Technologies™. All Rights Reserved. *
*******************************************************************************
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. *
* *
* This code is free software; you can redistribute it and/or modify it under *
* the terms of The MIT License (MIT), as published by the Open Source *
* Initiative. (See http://opensource.org/licenses/MIT) *
*******************************************************************************/
package elements
import (
uti "github.com/craterdog-bali/go-bali-document-notation/utilities"
)
// TAG INTERFACE
// This constructor creates a new random tag identifier element with the
// specified number of bytes.
func TagOfSize(size int) Tag {
if size < 1 {
panic("A tag must be at least one byte long!")
}
var bytes = uti.RandomBytes(size)
var tag = uti.Base32Encode(bytes)
return Tag(tag)
}
// This type defines the methods associated with a tag identifier that extends
// the native Go string type.
type Tag string
// SEQUENTIAL INTERFACE
// This method determines whether or not this tag is empty.
func (v Tag) IsEmpty() bool {
return false
}
// This method returns the number of bytes contained in this tag.
func (v Tag) GetSize() int {
return len(v.AsArray())
}
// This method returns all the bytes in this tag. The bytes retrieved
// are in the same order as they are in the tag.
func (v Tag) AsArray() []byte {
var encoded = string(v)
var bytes = uti.Base64Decode(encoded)
return bytes
}