Documentation
¶
Overview ¶
Package dotquote serializes data into the "dotquote" format.
The "dotquote" format is a more human-readable for a list of namespaced key-valued pairs.
The "dotquote" format is also useful for fitting your entire data on a single line of text.
Example
"app"."name"="myapi" "app"."build"."number"="23" "apple"="one" "banana"="two" "cherry"="three" "trace"."id"="DtehCQqBnw93Tw4h"
The example dotquote line could have been generated by the following code:
m := map[string]interface{}{
"app":map[string]interface{}{
"name":"myapi",
"build":map[string]interface{
"number":23,
},
},
"apple":"one",
"banana":"two",
"cherry":"three",
"trace":map[string]interface{}{
"id":"DtehCQqBnw93Tw4h",
},
}
var p []byte
p = dotquote.AppendMap(p, m)
Alternatively, it that example dotquote line could have been generated by the following code:
var p []byte p = dotquote.AppendString(p, "myapi", "app", "name") p = dotquote.AppendString(p, "23", "app", "build", "number") p = dotquote.AppendString(p, "one", "apple") p = dotquote.AppendString(p, "two", "banana") p = dotquote.AppendString(p, "three", "cherry") p = dotquote.AppendString(p, "DtehCQqBnw93Tw4h", "trace", "id")
Index ¶
- func Append(p []byte, value []byte, name ...[]byte) []byte
- func AppendMap(p []byte, mapData map[string]interface{}, namePrefix ...string) []byte
- func AppendString(p []byte, value string, name ...string) []byte
- func AppendStrings(p []byte, value []string, name ...string) []byte
- func Unmarshal(data []byte, v interface{}) error
- type Decoder
- func (decoder Decoder) Err() error
- func (decoder Decoder) Key() (int, int, error)
- func (decoder Decoder) KeyBytes() ([]byte, error)
- func (decoder Decoder) KeyString() (string, error)
- func (decoder Decoder) MustKey() (int, int)
- func (decoder Decoder) MustKeyBytes() []byte
- func (decoder Decoder) MustKeyString() string
- func (decoder *Decoder) Next() bool
- func (decoder *Decoder) Values() *DecoderValues
- type DecoderValues
- func (v DecoderValues) Err() error
- func (v DecoderValues) MustValue() (int, int)
- func (v DecoderValues) MustValueBytes() []byte
- func (v DecoderValues) MustValueString() string
- func (v *DecoderValues) Next() bool
- func (v DecoderValues) UnquotedValueString() (string, error)
- func (v DecoderValues) Value() (int, int, error)
- func (v DecoderValues) ValueBytes() ([]byte, error)
- func (v DecoderValues) ValueString() (string, error)
- type Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Decoder ¶
Decoder
Example usage:
decoder := Decoder{
Bytes: p,
}
for decoder.Next() {
keyBegin, keyEnd, err := decoder.Key()
if nil != err {
return err
}
key := p[keyBegin:keyEnd]
//@TODO: do something with the key
values := decoder.Values()
for values.Next() {
valueBegin, valueEnd, err := values.Value()
if nil != err {
return err
}
value := p[valueBegin:valueEnd]
/?@TOD: do something with the value.
}
if err := values.Err(); nil != err {
return err
}
}
if err := decoder.Err(); nil != err {
return nil
}
func (Decoder) KeyBytes ¶
KeyBytes returns a []byte to the current dotquote key.
Note that this is a slice on the []byte originally given to this decoder, in its "Bytes" field.
It is NOT a copy.
func (Decoder) MustKeyBytes ¶
MustKeyBytes is like the KeyBytes method, expect it panic()s on an error.
func (Decoder) MustKeyString ¶
MustKeyString is like the KeyString method, expect it panic()s on an error.
func (*Decoder) Values ¶
func (decoder *Decoder) Values() *DecoderValues
type DecoderValues ¶
type DecoderValues struct {
// contains filtered or unexported fields
}
func (DecoderValues) Err ¶
func (v DecoderValues) Err() error
func (DecoderValues) MustValue ¶
func (v DecoderValues) MustValue() (int, int)
MustValue is like Value, expect it panic()s on an error.
func (DecoderValues) MustValueBytes ¶
func (v DecoderValues) MustValueBytes() []byte
MustValueBytes is like ValueBytes, expect it panic()s on an error.
func (DecoderValues) MustValueString ¶
func (v DecoderValues) MustValueString() string
MustValueString is like ValueString, expect it panic()s on an error.
func (*DecoderValues) Next ¶
func (v *DecoderValues) Next() bool
func (DecoderValues) UnquotedValueString ¶
func (v DecoderValues) UnquotedValueString() (string, error)
func (DecoderValues) ValueBytes ¶
func (v DecoderValues) ValueBytes() ([]byte, error)
func (DecoderValues) ValueString ¶
func (v DecoderValues) ValueString() (string, error)