-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into modern-session-view
- Loading branch information
Showing
25 changed files
with
1,267 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package azureblobstorage | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
) | ||
|
||
// decoder is an interface for decoding data from an io.Reader. | ||
type decoder interface { | ||
// decode reads and decodes data from an io reader based on the codec type. | ||
// It returns the decoded data and an error if the data cannot be decoded. | ||
decode() ([]byte, error) | ||
// next advances the decoder to the next data item and returns true if there is more data to be decoded. | ||
next() bool | ||
// close closes the decoder and releases any resources associated with it. | ||
// It returns an error if the decoder cannot be closed. | ||
|
||
// more returns whether there are more records to read. | ||
more() bool | ||
|
||
close() error | ||
} | ||
|
||
// valueDecoder is a decoder that can decode directly to a JSON serialisable value. | ||
type valueDecoder interface { | ||
decoder | ||
|
||
decodeValue() ([]byte, map[string]any, error) | ||
} | ||
|
||
// newDecoder creates a new decoder based on the codec type. | ||
// It returns a decoder type and an error if the codec type is not supported. | ||
// If the reader config codec option is not set, it returns a nil decoder and nil error. | ||
func newDecoder(cfg decoderConfig, r io.Reader) (decoder, error) { | ||
switch { | ||
case cfg.Codec == nil: | ||
return nil, nil | ||
case cfg.Codec.CSV != nil: | ||
return newCSVDecoder(cfg, r) | ||
default: | ||
return nil, fmt.Errorf("unsupported config value: %v", cfg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package azureblobstorage | ||
|
||
import ( | ||
"fmt" | ||
"unicode/utf8" | ||
) | ||
|
||
// decoderConfig contains the configuration options for instantiating a decoder. | ||
type decoderConfig struct { | ||
Codec *codecConfig `config:"codec"` | ||
} | ||
|
||
// codecConfig contains the configuration options for different codecs used by a decoder. | ||
type codecConfig struct { | ||
CSV *csvCodecConfig `config:"csv"` | ||
} | ||
|
||
// csvCodecConfig contains the configuration options for the CSV codec. | ||
type csvCodecConfig struct { | ||
Enabled bool `config:"enabled"` | ||
|
||
// Fields is the set of field names. If it is present | ||
// it is used to specify the object names of returned | ||
// values and the FieldsPerRecord field in the csv.Reader. | ||
// Otherwise, names are obtained from the first | ||
// line of the CSV data. | ||
Fields []string `config:"fields_names"` | ||
|
||
// The fields below have the same meaning as the | ||
// fields of the same name in csv.Reader. | ||
Comma *configRune `config:"comma"` | ||
Comment configRune `config:"comment"` | ||
LazyQuotes bool `config:"lazy_quotes"` | ||
TrimLeadingSpace bool `config:"trim_leading_space"` | ||
} | ||
|
||
type configRune rune | ||
|
||
func (r *configRune) Unpack(s string) error { | ||
if s == "" { | ||
return nil | ||
} | ||
n := utf8.RuneCountInString(s) | ||
if n != 1 { | ||
return fmt.Errorf("single character option given more than one character: %q", s) | ||
} | ||
_r, _ := utf8.DecodeRuneInString(s) | ||
*r = configRune(_r) | ||
return nil | ||
} |
Oops, something went wrong.