types.go 590 B

1234567891011121314151617
  1. // Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package jsonutil
  5. // Bytes is a byte slice in a json-encoded struct.
  6. // encoding/json assumes that []byte fields are hex-encoded.
  7. // Bytes are not hex-encoded; they are treated the same as strings.
  8. // This can avoid unnecessary allocations due to a round trip through strings.
  9. type Bytes []byte
  10. func (b *Bytes) UnmarshalText(text []byte) error {
  11. // Copy the contexts of text.
  12. *b = append(*b, text...)
  13. return nil
  14. }