id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequencelengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
sequencelengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
150,700
Microsoft/go-winio
wim/wim.go
Readdir
func (f *File) Readdir() ([]*File, error) { if !f.IsDir() { return nil, errors.New("not a directory") } return f.img.readdir(f.subdirOffset) }
go
func (f *File) Readdir() ([]*File, error) { if !f.IsDir() { return nil, errors.New("not a directory") } return f.img.readdir(f.subdirOffset) }
[ "func", "(", "f", "*", "File", ")", "Readdir", "(", ")", "(", "[", "]", "*", "File", ",", "error", ")", "{", "if", "!", "f", ".", "IsDir", "(", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "f", ".", "img", ".", "readdir", "(", "f", ".", "subdirOffset", ")", "\n", "}" ]
// Readdir reads the directory entries.
[ "Readdir", "reads", "the", "directory", "entries", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/wim.go#L855-L860
150,701
Microsoft/go-winio
wim/lzx/lzx.go
feed
func (f *decompressor) feed() bool { err := f.ensureAtLeast(2) if err != nil { if err == io.ErrUnexpectedEOF { return false } } f.c |= (uint32(f.b[f.bo+1])<<8 | uint32(f.b[f.bo])) << (16 - f.nbits) f.nbits += 16 f.bo += 2 return true }
go
func (f *decompressor) feed() bool { err := f.ensureAtLeast(2) if err != nil { if err == io.ErrUnexpectedEOF { return false } } f.c |= (uint32(f.b[f.bo+1])<<8 | uint32(f.b[f.bo])) << (16 - f.nbits) f.nbits += 16 f.bo += 2 return true }
[ "func", "(", "f", "*", "decompressor", ")", "feed", "(", ")", "bool", "{", "err", ":=", "f", ".", "ensureAtLeast", "(", "2", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "ErrUnexpectedEOF", "{", "return", "false", "\n", "}", "\n", "}", "\n", "f", ".", "c", "|=", "(", "uint32", "(", "f", ".", "b", "[", "f", ".", "bo", "+", "1", "]", ")", "<<", "8", "|", "uint32", "(", "f", ".", "b", "[", "f", ".", "bo", "]", ")", ")", "<<", "(", "16", "-", "f", ".", "nbits", ")", "\n", "f", ".", "nbits", "+=", "16", "\n", "f", ".", "bo", "+=", "2", "\n", "return", "true", "\n", "}" ]
// feed retrieves another 16-bit word from the stream and consumes // it into f.c. It returns false if there are no more bytes available. // Otherwise, on error, it sets f.err.
[ "feed", "retrieves", "another", "16", "-", "bit", "word", "from", "the", "stream", "and", "consumes", "it", "into", "f", ".", "c", ".", "It", "returns", "false", "if", "there", "are", "no", "more", "bytes", "available", ".", "Otherwise", "on", "error", "it", "sets", "f", ".", "err", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L118-L129
150,702
Microsoft/go-winio
wim/lzx/lzx.go
getBits
func (f *decompressor) getBits(n byte) uint16 { if f.nbits < n { if !f.feed() { f.fail(io.ErrUnexpectedEOF) } } c := uint16(f.c >> (32 - n)) f.c <<= n f.nbits -= n return c }
go
func (f *decompressor) getBits(n byte) uint16 { if f.nbits < n { if !f.feed() { f.fail(io.ErrUnexpectedEOF) } } c := uint16(f.c >> (32 - n)) f.c <<= n f.nbits -= n return c }
[ "func", "(", "f", "*", "decompressor", ")", "getBits", "(", "n", "byte", ")", "uint16", "{", "if", "f", ".", "nbits", "<", "n", "{", "if", "!", "f", ".", "feed", "(", ")", "{", "f", ".", "fail", "(", "io", ".", "ErrUnexpectedEOF", ")", "\n", "}", "\n", "}", "\n", "c", ":=", "uint16", "(", "f", ".", "c", ">>", "(", "32", "-", "n", ")", ")", "\n", "f", ".", "c", "<<=", "n", "\n", "f", ".", "nbits", "-=", "n", "\n", "return", "c", "\n", "}" ]
// getBits retrieves the next n bits from the byte stream. n // must be <= 16. It sets f.err on error.
[ "getBits", "retrieves", "the", "next", "n", "bits", "from", "the", "byte", "stream", ".", "n", "must", "be", "<", "=", "16", ".", "It", "sets", "f", ".", "err", "on", "error", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L133-L143
150,703
Microsoft/go-winio
wim/lzx/lzx.go
getCode
func (f *decompressor) getCode(h *huffman) uint16 { if h.maxbits > 0 { if f.nbits < maxTreePathLen { f.feed() } // For codes with length < tablebits, it doesn't matter // what the remainder of the bits used for table lookup // are, since entries with all possible suffixes were // added to the table. c := h.table[f.c>>(32-tablebits)] if c >= 1<<lenshift { // The code is already in c. } else { c = h.extra[c][f.c<<tablebits>>(32-(h.maxbits-tablebits))] } n := byte(c >> lenshift) if f.nbits >= n { // Only consume the length of the code, not the maximum // code length. f.c <<= n f.nbits -= n return c & codemask } f.fail(io.ErrUnexpectedEOF) return 0 } // This is an empty tree. It should not be used. f.fail(errCorrupt) return 0 }
go
func (f *decompressor) getCode(h *huffman) uint16 { if h.maxbits > 0 { if f.nbits < maxTreePathLen { f.feed() } // For codes with length < tablebits, it doesn't matter // what the remainder of the bits used for table lookup // are, since entries with all possible suffixes were // added to the table. c := h.table[f.c>>(32-tablebits)] if c >= 1<<lenshift { // The code is already in c. } else { c = h.extra[c][f.c<<tablebits>>(32-(h.maxbits-tablebits))] } n := byte(c >> lenshift) if f.nbits >= n { // Only consume the length of the code, not the maximum // code length. f.c <<= n f.nbits -= n return c & codemask } f.fail(io.ErrUnexpectedEOF) return 0 } // This is an empty tree. It should not be used. f.fail(errCorrupt) return 0 }
[ "func", "(", "f", "*", "decompressor", ")", "getCode", "(", "h", "*", "huffman", ")", "uint16", "{", "if", "h", ".", "maxbits", ">", "0", "{", "if", "f", ".", "nbits", "<", "maxTreePathLen", "{", "f", ".", "feed", "(", ")", "\n", "}", "\n\n", "// For codes with length < tablebits, it doesn't matter", "// what the remainder of the bits used for table lookup", "// are, since entries with all possible suffixes were", "// added to the table.", "c", ":=", "h", ".", "table", "[", "f", ".", "c", ">>", "(", "32", "-", "tablebits", ")", "]", "\n", "if", "c", ">=", "1", "<<", "lenshift", "{", "// The code is already in c.", "}", "else", "{", "c", "=", "h", ".", "extra", "[", "c", "]", "[", "f", ".", "c", "<<", "tablebits", ">>", "(", "32", "-", "(", "h", ".", "maxbits", "-", "tablebits", ")", ")", "]", "\n", "}", "\n\n", "n", ":=", "byte", "(", "c", ">>", "lenshift", ")", "\n", "if", "f", ".", "nbits", ">=", "n", "{", "// Only consume the length of the code, not the maximum", "// code length.", "f", ".", "c", "<<=", "n", "\n", "f", ".", "nbits", "-=", "n", "\n", "return", "c", "&", "codemask", "\n", "}", "\n\n", "f", ".", "fail", "(", "io", ".", "ErrUnexpectedEOF", ")", "\n", "return", "0", "\n", "}", "\n\n", "// This is an empty tree. It should not be used.", "f", ".", "fail", "(", "errCorrupt", ")", "\n", "return", "0", "\n", "}" ]
// getCode retrieves the next code using the provided // huffman tree. It sets f.err on error.
[ "getCode", "retrieves", "the", "next", "code", "using", "the", "provided", "huffman", "tree", ".", "It", "sets", "f", ".", "err", "on", "error", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L224-L257
150,704
Microsoft/go-winio
wim/lzx/lzx.go
readTree
func (f *decompressor) readTree(lens []byte) error { // Get the pre-tree for the main tree. var pretreeLen [20]byte for i := range pretreeLen { pretreeLen[i] = byte(f.getBits(4)) } if f.err != nil { return f.err } h := buildTable(pretreeLen[:]) // The lengths are encoded as a series of huffman codes // encoded by the pre-tree. for i := 0; i < len(lens); { c := byte(f.getCode(h)) if f.err != nil { return f.err } switch { case c <= 16: // length is delta from previous length lens[i] = (lens[i] + 17 - c) % 17 i++ case c == 17: // next n + 4 lengths are zero zeroes := int(f.getBits(4)) + 4 if i+zeroes > len(lens) { return errCorrupt } for j := 0; j < zeroes; j++ { lens[i+j] = 0 } i += zeroes case c == 18: // next n + 20 lengths are zero zeroes := int(f.getBits(5)) + 20 if i+zeroes > len(lens) { return errCorrupt } for j := 0; j < zeroes; j++ { lens[i+j] = 0 } i += zeroes case c == 19: // next n + 4 lengths all have the same value same := int(f.getBits(1)) + 4 if i+same > len(lens) { return errCorrupt } c = byte(f.getCode(h)) if c > 16 { return errCorrupt } l := (lens[i] + 17 - c) % 17 for j := 0; j < same; j++ { lens[i+j] = l } i += same default: return errCorrupt } } if f.err != nil { return f.err } return nil }
go
func (f *decompressor) readTree(lens []byte) error { // Get the pre-tree for the main tree. var pretreeLen [20]byte for i := range pretreeLen { pretreeLen[i] = byte(f.getBits(4)) } if f.err != nil { return f.err } h := buildTable(pretreeLen[:]) // The lengths are encoded as a series of huffman codes // encoded by the pre-tree. for i := 0; i < len(lens); { c := byte(f.getCode(h)) if f.err != nil { return f.err } switch { case c <= 16: // length is delta from previous length lens[i] = (lens[i] + 17 - c) % 17 i++ case c == 17: // next n + 4 lengths are zero zeroes := int(f.getBits(4)) + 4 if i+zeroes > len(lens) { return errCorrupt } for j := 0; j < zeroes; j++ { lens[i+j] = 0 } i += zeroes case c == 18: // next n + 20 lengths are zero zeroes := int(f.getBits(5)) + 20 if i+zeroes > len(lens) { return errCorrupt } for j := 0; j < zeroes; j++ { lens[i+j] = 0 } i += zeroes case c == 19: // next n + 4 lengths all have the same value same := int(f.getBits(1)) + 4 if i+same > len(lens) { return errCorrupt } c = byte(f.getCode(h)) if c > 16 { return errCorrupt } l := (lens[i] + 17 - c) % 17 for j := 0; j < same; j++ { lens[i+j] = l } i += same default: return errCorrupt } } if f.err != nil { return f.err } return nil }
[ "func", "(", "f", "*", "decompressor", ")", "readTree", "(", "lens", "[", "]", "byte", ")", "error", "{", "// Get the pre-tree for the main tree.", "var", "pretreeLen", "[", "20", "]", "byte", "\n", "for", "i", ":=", "range", "pretreeLen", "{", "pretreeLen", "[", "i", "]", "=", "byte", "(", "f", ".", "getBits", "(", "4", ")", ")", "\n", "}", "\n", "if", "f", ".", "err", "!=", "nil", "{", "return", "f", ".", "err", "\n", "}", "\n", "h", ":=", "buildTable", "(", "pretreeLen", "[", ":", "]", ")", "\n\n", "// The lengths are encoded as a series of huffman codes", "// encoded by the pre-tree.", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "lens", ")", ";", "{", "c", ":=", "byte", "(", "f", ".", "getCode", "(", "h", ")", ")", "\n", "if", "f", ".", "err", "!=", "nil", "{", "return", "f", ".", "err", "\n", "}", "\n", "switch", "{", "case", "c", "<=", "16", ":", "// length is delta from previous length", "lens", "[", "i", "]", "=", "(", "lens", "[", "i", "]", "+", "17", "-", "c", ")", "%", "17", "\n", "i", "++", "\n", "case", "c", "==", "17", ":", "// next n + 4 lengths are zero", "zeroes", ":=", "int", "(", "f", ".", "getBits", "(", "4", ")", ")", "+", "4", "\n", "if", "i", "+", "zeroes", ">", "len", "(", "lens", ")", "{", "return", "errCorrupt", "\n", "}", "\n", "for", "j", ":=", "0", ";", "j", "<", "zeroes", ";", "j", "++", "{", "lens", "[", "i", "+", "j", "]", "=", "0", "\n", "}", "\n", "i", "+=", "zeroes", "\n", "case", "c", "==", "18", ":", "// next n + 20 lengths are zero", "zeroes", ":=", "int", "(", "f", ".", "getBits", "(", "5", ")", ")", "+", "20", "\n", "if", "i", "+", "zeroes", ">", "len", "(", "lens", ")", "{", "return", "errCorrupt", "\n", "}", "\n", "for", "j", ":=", "0", ";", "j", "<", "zeroes", ";", "j", "++", "{", "lens", "[", "i", "+", "j", "]", "=", "0", "\n", "}", "\n", "i", "+=", "zeroes", "\n", "case", "c", "==", "19", ":", "// next n + 4 lengths all have the same value", "same", ":=", "int", "(", "f", ".", "getBits", "(", "1", ")", ")", "+", "4", "\n", "if", "i", "+", "same", ">", "len", "(", "lens", ")", "{", "return", "errCorrupt", "\n", "}", "\n", "c", "=", "byte", "(", "f", ".", "getCode", "(", "h", ")", ")", "\n", "if", "c", ">", "16", "{", "return", "errCorrupt", "\n", "}", "\n", "l", ":=", "(", "lens", "[", "i", "]", "+", "17", "-", "c", ")", "%", "17", "\n", "for", "j", ":=", "0", ";", "j", "<", "same", ";", "j", "++", "{", "lens", "[", "i", "+", "j", "]", "=", "l", "\n", "}", "\n", "i", "+=", "same", "\n", "default", ":", "return", "errCorrupt", "\n", "}", "\n", "}", "\n\n", "if", "f", ".", "err", "!=", "nil", "{", "return", "f", ".", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// readTree updates the huffman tree path lengths in lens by // reading and decoding lengths from the byte stream. lens // should be prepopulated with the previous block's tree's path // lengths. For the first block, lens should be zero.
[ "readTree", "updates", "the", "huffman", "tree", "path", "lengths", "in", "lens", "by", "reading", "and", "decoding", "lengths", "from", "the", "byte", "stream", ".", "lens", "should", "be", "prepopulated", "with", "the", "previous", "block", "s", "tree", "s", "path", "lengths", ".", "For", "the", "first", "block", "lens", "should", "be", "zero", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L263-L326
150,705
Microsoft/go-winio
wim/lzx/lzx.go
readTrees
func (f *decompressor) readTrees(readAligned bool) (main *huffman, length *huffman, aligned *huffman, err error) { // Aligned offset blocks start with a small aligned offset tree. if readAligned { var alignedLen [8]byte for i := range alignedLen { alignedLen[i] = byte(f.getBits(3)) } aligned = buildTable(alignedLen[:]) if aligned == nil { err = errors.New("corrupt") return } } // The main tree is encoded in two parts. err = f.readTree(f.mainlens[:maincodesplit]) if err != nil { return } err = f.readTree(f.mainlens[maincodesplit:]) if err != nil { return } main = buildTable(f.mainlens[:]) if main == nil { err = errors.New("corrupt") return } // The length tree is encoding in a single part. err = f.readTree(f.lenlens[:]) if err != nil { return } length = buildTable(f.lenlens[:]) if length == nil { err = errors.New("corrupt") return } err = f.err return }
go
func (f *decompressor) readTrees(readAligned bool) (main *huffman, length *huffman, aligned *huffman, err error) { // Aligned offset blocks start with a small aligned offset tree. if readAligned { var alignedLen [8]byte for i := range alignedLen { alignedLen[i] = byte(f.getBits(3)) } aligned = buildTable(alignedLen[:]) if aligned == nil { err = errors.New("corrupt") return } } // The main tree is encoded in two parts. err = f.readTree(f.mainlens[:maincodesplit]) if err != nil { return } err = f.readTree(f.mainlens[maincodesplit:]) if err != nil { return } main = buildTable(f.mainlens[:]) if main == nil { err = errors.New("corrupt") return } // The length tree is encoding in a single part. err = f.readTree(f.lenlens[:]) if err != nil { return } length = buildTable(f.lenlens[:]) if length == nil { err = errors.New("corrupt") return } err = f.err return }
[ "func", "(", "f", "*", "decompressor", ")", "readTrees", "(", "readAligned", "bool", ")", "(", "main", "*", "huffman", ",", "length", "*", "huffman", ",", "aligned", "*", "huffman", ",", "err", "error", ")", "{", "// Aligned offset blocks start with a small aligned offset tree.", "if", "readAligned", "{", "var", "alignedLen", "[", "8", "]", "byte", "\n", "for", "i", ":=", "range", "alignedLen", "{", "alignedLen", "[", "i", "]", "=", "byte", "(", "f", ".", "getBits", "(", "3", ")", ")", "\n", "}", "\n", "aligned", "=", "buildTable", "(", "alignedLen", "[", ":", "]", ")", "\n", "if", "aligned", "==", "nil", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "}", "\n\n", "// The main tree is encoded in two parts.", "err", "=", "f", ".", "readTree", "(", "f", ".", "mainlens", "[", ":", "maincodesplit", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "err", "=", "f", ".", "readTree", "(", "f", ".", "mainlens", "[", "maincodesplit", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "main", "=", "buildTable", "(", "f", ".", "mainlens", "[", ":", "]", ")", "\n", "if", "main", "==", "nil", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "// The length tree is encoding in a single part.", "err", "=", "f", ".", "readTree", "(", "f", ".", "lenlens", "[", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "length", "=", "buildTable", "(", "f", ".", "lenlens", "[", ":", "]", ")", "\n", "if", "length", "==", "nil", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "err", "=", "f", ".", "err", "\n", "return", "\n", "}" ]
// readTrees reads the two or three huffman trees for the current block. // readAligned specifies whether to read the aligned offset tree.
[ "readTrees", "reads", "the", "two", "or", "three", "huffman", "trees", "for", "the", "current", "block", ".", "readAligned", "specifies", "whether", "to", "read", "the", "aligned", "offset", "tree", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L393-L437
150,706
Microsoft/go-winio
wim/lzx/lzx.go
readCompressedBlock
func (f *decompressor) readCompressedBlock(start, end uint16, hmain, hlength, haligned *huffman) (int, error) { i := start for i < end { main := f.getCode(hmain) if f.err != nil { break } if main < 256 { // Literal byte. f.window[i] = byte(main) i++ continue } // This is a match backward in the window. Determine // the offset and dlength. matchlen := (main - 256) % 8 slot := (main - 256) / 8 // The length is either the low bits of the code, // or if this is 7, is encoded with the length tree. if matchlen == 7 { matchlen += f.getCode(hlength) } matchlen += 2 var matchoffset uint16 if slot < 3 { // The offset is one of the LRU values. matchoffset = f.lru[slot] f.lru[slot] = f.lru[0] f.lru[0] = matchoffset } else { // The offset is encoded as a combination of the // slot and more bits from the bit stream. offsetbits := footerBits[slot] var verbatimbits, alignedbits uint16 if offsetbits > 0 { if haligned != nil && offsetbits >= 3 { // This is an aligned offset block. Combine // the bits written verbatim with the aligned // offset tree code. verbatimbits = f.getBits(offsetbits-3) * 8 alignedbits = f.getCode(haligned) } else { // There are no aligned offset bits to read, // only verbatim bits. verbatimbits = f.getBits(offsetbits) alignedbits = 0 } } matchoffset = basePosition[slot] + verbatimbits + alignedbits - 2 // Update the LRU cache. f.lru[2] = f.lru[1] f.lru[1] = f.lru[0] f.lru[0] = matchoffset } if matchoffset <= i && matchlen <= end-i { copyend := i + matchlen for ; i < copyend; i++ { f.window[i] = f.window[i-matchoffset] } } else { f.fail(errCorrupt) break } } return int(i - start), f.err }
go
func (f *decompressor) readCompressedBlock(start, end uint16, hmain, hlength, haligned *huffman) (int, error) { i := start for i < end { main := f.getCode(hmain) if f.err != nil { break } if main < 256 { // Literal byte. f.window[i] = byte(main) i++ continue } // This is a match backward in the window. Determine // the offset and dlength. matchlen := (main - 256) % 8 slot := (main - 256) / 8 // The length is either the low bits of the code, // or if this is 7, is encoded with the length tree. if matchlen == 7 { matchlen += f.getCode(hlength) } matchlen += 2 var matchoffset uint16 if slot < 3 { // The offset is one of the LRU values. matchoffset = f.lru[slot] f.lru[slot] = f.lru[0] f.lru[0] = matchoffset } else { // The offset is encoded as a combination of the // slot and more bits from the bit stream. offsetbits := footerBits[slot] var verbatimbits, alignedbits uint16 if offsetbits > 0 { if haligned != nil && offsetbits >= 3 { // This is an aligned offset block. Combine // the bits written verbatim with the aligned // offset tree code. verbatimbits = f.getBits(offsetbits-3) * 8 alignedbits = f.getCode(haligned) } else { // There are no aligned offset bits to read, // only verbatim bits. verbatimbits = f.getBits(offsetbits) alignedbits = 0 } } matchoffset = basePosition[slot] + verbatimbits + alignedbits - 2 // Update the LRU cache. f.lru[2] = f.lru[1] f.lru[1] = f.lru[0] f.lru[0] = matchoffset } if matchoffset <= i && matchlen <= end-i { copyend := i + matchlen for ; i < copyend; i++ { f.window[i] = f.window[i-matchoffset] } } else { f.fail(errCorrupt) break } } return int(i - start), f.err }
[ "func", "(", "f", "*", "decompressor", ")", "readCompressedBlock", "(", "start", ",", "end", "uint16", ",", "hmain", ",", "hlength", ",", "haligned", "*", "huffman", ")", "(", "int", ",", "error", ")", "{", "i", ":=", "start", "\n", "for", "i", "<", "end", "{", "main", ":=", "f", ".", "getCode", "(", "hmain", ")", "\n", "if", "f", ".", "err", "!=", "nil", "{", "break", "\n", "}", "\n", "if", "main", "<", "256", "{", "// Literal byte.", "f", ".", "window", "[", "i", "]", "=", "byte", "(", "main", ")", "\n", "i", "++", "\n", "continue", "\n", "}", "\n\n", "// This is a match backward in the window. Determine", "// the offset and dlength.", "matchlen", ":=", "(", "main", "-", "256", ")", "%", "8", "\n", "slot", ":=", "(", "main", "-", "256", ")", "/", "8", "\n\n", "// The length is either the low bits of the code,", "// or if this is 7, is encoded with the length tree.", "if", "matchlen", "==", "7", "{", "matchlen", "+=", "f", ".", "getCode", "(", "hlength", ")", "\n", "}", "\n", "matchlen", "+=", "2", "\n\n", "var", "matchoffset", "uint16", "\n", "if", "slot", "<", "3", "{", "// The offset is one of the LRU values.", "matchoffset", "=", "f", ".", "lru", "[", "slot", "]", "\n", "f", ".", "lru", "[", "slot", "]", "=", "f", ".", "lru", "[", "0", "]", "\n", "f", ".", "lru", "[", "0", "]", "=", "matchoffset", "\n", "}", "else", "{", "// The offset is encoded as a combination of the", "// slot and more bits from the bit stream.", "offsetbits", ":=", "footerBits", "[", "slot", "]", "\n", "var", "verbatimbits", ",", "alignedbits", "uint16", "\n", "if", "offsetbits", ">", "0", "{", "if", "haligned", "!=", "nil", "&&", "offsetbits", ">=", "3", "{", "// This is an aligned offset block. Combine", "// the bits written verbatim with the aligned", "// offset tree code.", "verbatimbits", "=", "f", ".", "getBits", "(", "offsetbits", "-", "3", ")", "*", "8", "\n", "alignedbits", "=", "f", ".", "getCode", "(", "haligned", ")", "\n", "}", "else", "{", "// There are no aligned offset bits to read,", "// only verbatim bits.", "verbatimbits", "=", "f", ".", "getBits", "(", "offsetbits", ")", "\n", "alignedbits", "=", "0", "\n", "}", "\n", "}", "\n", "matchoffset", "=", "basePosition", "[", "slot", "]", "+", "verbatimbits", "+", "alignedbits", "-", "2", "\n", "// Update the LRU cache.", "f", ".", "lru", "[", "2", "]", "=", "f", ".", "lru", "[", "1", "]", "\n", "f", ".", "lru", "[", "1", "]", "=", "f", ".", "lru", "[", "0", "]", "\n", "f", ".", "lru", "[", "0", "]", "=", "matchoffset", "\n", "}", "\n\n", "if", "matchoffset", "<=", "i", "&&", "matchlen", "<=", "end", "-", "i", "{", "copyend", ":=", "i", "+", "matchlen", "\n", "for", ";", "i", "<", "copyend", ";", "i", "++", "{", "f", ".", "window", "[", "i", "]", "=", "f", ".", "window", "[", "i", "-", "matchoffset", "]", "\n", "}", "\n", "}", "else", "{", "f", ".", "fail", "(", "errCorrupt", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "return", "int", "(", "i", "-", "start", ")", ",", "f", ".", "err", "\n", "}" ]
// readCompressedBlock decodes a compressed block, writing into the window // starting at start and ending at end, and using the provided huffman trees.
[ "readCompressedBlock", "decodes", "a", "compressed", "block", "writing", "into", "the", "window", "starting", "at", "start", "and", "ending", "at", "end", "and", "using", "the", "provided", "huffman", "trees", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L441-L510
150,707
Microsoft/go-winio
wim/lzx/lzx.go
readBlock
func (f *decompressor) readBlock(start uint16) (int, error) { blockType, size, err := f.readBlockHeader() if err != nil { return 0, err } if blockType == uncompressedBlock { if size%2 == 1 { // Remember to realign the byte stream at the next block. f.unaligned = true } copied := 0 if f.bo < f.bv { copied = int(size) s := int(start) if copied > f.bv-f.bo { copied = f.bv - f.bo } copy(f.window[s:s+copied], f.b[f.bo:f.bo+copied]) f.bo += copied } n, err := io.ReadFull(f.r, f.window[start+uint16(copied):start+size]) return copied + n, err } hmain, hlength, haligned, err := f.readTrees(blockType == alignedOffsetBlock) if err != nil { return 0, err } return f.readCompressedBlock(start, start+size, hmain, hlength, haligned) }
go
func (f *decompressor) readBlock(start uint16) (int, error) { blockType, size, err := f.readBlockHeader() if err != nil { return 0, err } if blockType == uncompressedBlock { if size%2 == 1 { // Remember to realign the byte stream at the next block. f.unaligned = true } copied := 0 if f.bo < f.bv { copied = int(size) s := int(start) if copied > f.bv-f.bo { copied = f.bv - f.bo } copy(f.window[s:s+copied], f.b[f.bo:f.bo+copied]) f.bo += copied } n, err := io.ReadFull(f.r, f.window[start+uint16(copied):start+size]) return copied + n, err } hmain, hlength, haligned, err := f.readTrees(blockType == alignedOffsetBlock) if err != nil { return 0, err } return f.readCompressedBlock(start, start+size, hmain, hlength, haligned) }
[ "func", "(", "f", "*", "decompressor", ")", "readBlock", "(", "start", "uint16", ")", "(", "int", ",", "error", ")", "{", "blockType", ",", "size", ",", "err", ":=", "f", ".", "readBlockHeader", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "if", "blockType", "==", "uncompressedBlock", "{", "if", "size", "%", "2", "==", "1", "{", "// Remember to realign the byte stream at the next block.", "f", ".", "unaligned", "=", "true", "\n", "}", "\n", "copied", ":=", "0", "\n", "if", "f", ".", "bo", "<", "f", ".", "bv", "{", "copied", "=", "int", "(", "size", ")", "\n", "s", ":=", "int", "(", "start", ")", "\n", "if", "copied", ">", "f", ".", "bv", "-", "f", ".", "bo", "{", "copied", "=", "f", ".", "bv", "-", "f", ".", "bo", "\n", "}", "\n", "copy", "(", "f", ".", "window", "[", "s", ":", "s", "+", "copied", "]", ",", "f", ".", "b", "[", "f", ".", "bo", ":", "f", ".", "bo", "+", "copied", "]", ")", "\n", "f", ".", "bo", "+=", "copied", "\n", "}", "\n", "n", ",", "err", ":=", "io", ".", "ReadFull", "(", "f", ".", "r", ",", "f", ".", "window", "[", "start", "+", "uint16", "(", "copied", ")", ":", "start", "+", "size", "]", ")", "\n", "return", "copied", "+", "n", ",", "err", "\n", "}", "\n\n", "hmain", ",", "hlength", ",", "haligned", ",", "err", ":=", "f", ".", "readTrees", "(", "blockType", "==", "alignedOffsetBlock", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "f", ".", "readCompressedBlock", "(", "start", ",", "start", "+", "size", ",", "hmain", ",", "hlength", ",", "haligned", ")", "\n", "}" ]
// readBlock decodes the current block and returns the number of uncompressed bytes.
[ "readBlock", "decodes", "the", "current", "block", "and", "returns", "the", "number", "of", "uncompressed", "bytes", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L513-L544
150,708
Microsoft/go-winio
wim/lzx/lzx.go
decodeE8
func decodeE8(b []byte, off int64) { if off > maxe8offset || len(b) < 10 { return } for i := 0; i < len(b)-10; i++ { if b[i] == 0xe8 { currentPtr := int32(off) + int32(i) abs := int32(binary.LittleEndian.Uint32(b[i+1 : i+5])) if abs >= -currentPtr && abs < e8filesize { var rel int32 if abs >= 0 { rel = abs - currentPtr } else { rel = abs + e8filesize } binary.LittleEndian.PutUint32(b[i+1:i+5], uint32(rel)) } i += 4 } } }
go
func decodeE8(b []byte, off int64) { if off > maxe8offset || len(b) < 10 { return } for i := 0; i < len(b)-10; i++ { if b[i] == 0xe8 { currentPtr := int32(off) + int32(i) abs := int32(binary.LittleEndian.Uint32(b[i+1 : i+5])) if abs >= -currentPtr && abs < e8filesize { var rel int32 if abs >= 0 { rel = abs - currentPtr } else { rel = abs + e8filesize } binary.LittleEndian.PutUint32(b[i+1:i+5], uint32(rel)) } i += 4 } } }
[ "func", "decodeE8", "(", "b", "[", "]", "byte", ",", "off", "int64", ")", "{", "if", "off", ">", "maxe8offset", "||", "len", "(", "b", ")", "<", "10", "{", "return", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "b", ")", "-", "10", ";", "i", "++", "{", "if", "b", "[", "i", "]", "==", "0xe8", "{", "currentPtr", ":=", "int32", "(", "off", ")", "+", "int32", "(", "i", ")", "\n", "abs", ":=", "int32", "(", "binary", ".", "LittleEndian", ".", "Uint32", "(", "b", "[", "i", "+", "1", ":", "i", "+", "5", "]", ")", ")", "\n", "if", "abs", ">=", "-", "currentPtr", "&&", "abs", "<", "e8filesize", "{", "var", "rel", "int32", "\n", "if", "abs", ">=", "0", "{", "rel", "=", "abs", "-", "currentPtr", "\n", "}", "else", "{", "rel", "=", "abs", "+", "e8filesize", "\n", "}", "\n", "binary", ".", "LittleEndian", ".", "PutUint32", "(", "b", "[", "i", "+", "1", ":", "i", "+", "5", "]", ",", "uint32", "(", "rel", ")", ")", "\n", "}", "\n", "i", "+=", "4", "\n", "}", "\n", "}", "\n", "}" ]
// decodeE8 reverses the 0xe8 x86 instruction encoding that was performed // to the uncompressed data before it was compressed.
[ "decodeE8", "reverses", "the", "0xe8", "x86", "instruction", "encoding", "that", "was", "performed", "to", "the", "uncompressed", "data", "before", "it", "was", "compressed", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L548-L568
150,709
Microsoft/go-winio
wim/lzx/lzx.go
NewReader
func NewReader(r io.Reader, uncompressedSize int) (io.ReadCloser, error) { if uncompressedSize > windowSize { return nil, errors.New("uncompressed size is limited to 32KB") } f := &decompressor{ lru: [3]uint16{1, 1, 1}, uncompressed: uncompressedSize, b: make([]byte, 4096), r: r, } return f, nil }
go
func NewReader(r io.Reader, uncompressedSize int) (io.ReadCloser, error) { if uncompressedSize > windowSize { return nil, errors.New("uncompressed size is limited to 32KB") } f := &decompressor{ lru: [3]uint16{1, 1, 1}, uncompressed: uncompressedSize, b: make([]byte, 4096), r: r, } return f, nil }
[ "func", "NewReader", "(", "r", "io", ".", "Reader", ",", "uncompressedSize", "int", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "if", "uncompressedSize", ">", "windowSize", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "f", ":=", "&", "decompressor", "{", "lru", ":", "[", "3", "]", "uint16", "{", "1", ",", "1", ",", "1", "}", ",", "uncompressed", ":", "uncompressedSize", ",", "b", ":", "make", "(", "[", "]", "byte", ",", "4096", ")", ",", "r", ":", "r", ",", "}", "\n", "return", "f", ",", "nil", "\n", "}" ]
// NewReader returns a new io.ReadCloser that decompresses a // WIM LZX stream until uncompressedSize bytes have been returned.
[ "NewReader", "returns", "a", "new", "io", ".", "ReadCloser", "that", "decompresses", "a", "WIM", "LZX", "stream", "until", "uncompressedSize", "bytes", "have", "been", "returned", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/wim/lzx/lzx.go#L595-L606
150,710
Microsoft/go-winio
pkg/guid/guid.go
FromString
func FromString(s string) (*GUID, error) { if len(s) != 36 { return nil, errors.New("invalid GUID format (length)") } if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' { return nil, errors.New("invalid GUID format (dashes)") } var g GUID data1, err := strconv.ParseUint(s[0:8], 16, 32) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data1)") } g.Data1 = uint32(data1) data2, err := strconv.ParseUint(s[9:13], 16, 16) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data2)") } g.Data2 = uint16(data2) data3, err := strconv.ParseUint(s[14:18], 16, 16) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data3)") } g.Data3 = uint16(data3) for i, x := range []int{19, 21, 24, 26, 28, 30, 32, 34} { v, err := strconv.ParseUint(s[x:x+2], 16, 8) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data4)") } g.Data4[i] = uint8(v) } return &g, nil }
go
func FromString(s string) (*GUID, error) { if len(s) != 36 { return nil, errors.New("invalid GUID format (length)") } if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' { return nil, errors.New("invalid GUID format (dashes)") } var g GUID data1, err := strconv.ParseUint(s[0:8], 16, 32) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data1)") } g.Data1 = uint32(data1) data2, err := strconv.ParseUint(s[9:13], 16, 16) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data2)") } g.Data2 = uint16(data2) data3, err := strconv.ParseUint(s[14:18], 16, 16) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data3)") } g.Data3 = uint16(data3) for i, x := range []int{19, 21, 24, 26, 28, 30, 32, 34} { v, err := strconv.ParseUint(s[x:x+2], 16, 8) if err != nil { return nil, errors.Wrap(err, "invalid GUID format (Data4)") } g.Data4[i] = uint8(v) } return &g, nil }
[ "func", "FromString", "(", "s", "string", ")", "(", "*", "GUID", ",", "error", ")", "{", "if", "len", "(", "s", ")", "!=", "36", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "s", "[", "8", "]", "!=", "'-'", "||", "s", "[", "13", "]", "!=", "'-'", "||", "s", "[", "18", "]", "!=", "'-'", "||", "s", "[", "23", "]", "!=", "'-'", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "var", "g", "GUID", "\n\n", "data1", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "s", "[", "0", ":", "8", "]", ",", "16", ",", "32", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "g", ".", "Data1", "=", "uint32", "(", "data1", ")", "\n\n", "data2", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "s", "[", "9", ":", "13", "]", ",", "16", ",", "16", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "g", ".", "Data2", "=", "uint16", "(", "data2", ")", "\n\n", "data3", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "s", "[", "14", ":", "18", "]", ",", "16", ",", "16", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "g", ".", "Data3", "=", "uint16", "(", "data3", ")", "\n\n", "for", "i", ",", "x", ":=", "range", "[", "]", "int", "{", "19", ",", "21", ",", "24", ",", "26", ",", "28", ",", "30", ",", "32", ",", "34", "}", "{", "v", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "s", "[", "x", ":", "x", "+", "2", "]", ",", "16", ",", "8", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "g", ".", "Data4", "[", "i", "]", "=", "uint8", "(", "v", ")", "\n", "}", "\n\n", "return", "&", "g", ",", "nil", "\n", "}" ]
// FromString parses a string containing a GUID and returns the GUID. The only // format currently supported is the `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` // format.
[ "FromString", "parses", "a", "string", "containing", "a", "GUID", "and", "returns", "the", "GUID", ".", "The", "only", "format", "currently", "supported", "is", "the", "xxxxxxxx", "-", "xxxx", "-", "xxxx", "-", "xxxx", "-", "xxxxxxxxxxxx", "format", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/guid/guid.go#L56-L93
150,711
Microsoft/go-winio
pkg/guid/guid.go
UnmarshalJSON
func (g *GUID) UnmarshalJSON(data []byte) error { g2, err := FromString(strings.Trim(string(data), "\"")) if err != nil { return err } *g = *g2 return nil }
go
func (g *GUID) UnmarshalJSON(data []byte) error { g2, err := FromString(strings.Trim(string(data), "\"")) if err != nil { return err } *g = *g2 return nil }
[ "func", "(", "g", "*", "GUID", ")", "UnmarshalJSON", "(", "data", "[", "]", "byte", ")", "error", "{", "g2", ",", "err", ":=", "FromString", "(", "strings", ".", "Trim", "(", "string", "(", "data", ")", ",", "\"", "\\\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "*", "g", "=", "*", "g2", "\n", "return", "nil", "\n", "}" ]
// UnmarshalJSON unmarshals a GUID from JSON representation and sets itself to // the unmarshaled GUID.
[ "UnmarshalJSON", "unmarshals", "a", "GUID", "from", "JSON", "representation", "and", "sets", "itself", "to", "the", "unmarshaled", "GUID", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/guid/guid.go#L103-L110
150,712
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
tmpVar
func (p *Param) tmpVar() string { if p.tmpVarIdx < 0 { p.tmpVarIdx = p.fn.curTmpVarIdx p.fn.curTmpVarIdx++ } return fmt.Sprintf("_p%d", p.tmpVarIdx) }
go
func (p *Param) tmpVar() string { if p.tmpVarIdx < 0 { p.tmpVarIdx = p.fn.curTmpVarIdx p.fn.curTmpVarIdx++ } return fmt.Sprintf("_p%d", p.tmpVarIdx) }
[ "func", "(", "p", "*", "Param", ")", "tmpVar", "(", ")", "string", "{", "if", "p", ".", "tmpVarIdx", "<", "0", "{", "p", ".", "tmpVarIdx", "=", "p", ".", "fn", ".", "curTmpVarIdx", "\n", "p", ".", "fn", ".", "curTmpVarIdx", "++", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "p", ".", "tmpVarIdx", ")", "\n", "}" ]
// tmpVar returns temp variable name that will be used to represent p during syscall.
[ "tmpVar", "returns", "temp", "variable", "name", "that", "will", "be", "used", "to", "represent", "p", "during", "syscall", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L100-L106
150,713
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
BoolTmpVarCode
func (p *Param) BoolTmpVarCode() string { const code = `var %s uint32 if %s { %s = 1 } else { %s = 0 }` tmp := p.tmpVar() return fmt.Sprintf(code, tmp, p.Name, tmp, tmp) }
go
func (p *Param) BoolTmpVarCode() string { const code = `var %s uint32 if %s { %s = 1 } else { %s = 0 }` tmp := p.tmpVar() return fmt.Sprintf(code, tmp, p.Name, tmp, tmp) }
[ "func", "(", "p", "*", "Param", ")", "BoolTmpVarCode", "(", ")", "string", "{", "const", "code", "=", "`var %s uint32\n\tif %s {\n\t\t%s = 1\n\t} else {\n\t\t%s = 0\n\t}`", "\n", "tmp", ":=", "p", ".", "tmpVar", "(", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "code", ",", "tmp", ",", "p", ".", "Name", ",", "tmp", ",", "tmp", ")", "\n", "}" ]
// BoolTmpVarCode returns source code for bool temp variable.
[ "BoolTmpVarCode", "returns", "source", "code", "for", "bool", "temp", "variable", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L109-L118
150,714
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
SliceTmpVarCode
func (p *Param) SliceTmpVarCode() string { const code = `var %s *%s if len(%s) > 0 { %s = &%s[0] }` tmp := p.tmpVar() return fmt.Sprintf(code, tmp, p.Type[2:], p.Name, tmp, p.Name) }
go
func (p *Param) SliceTmpVarCode() string { const code = `var %s *%s if len(%s) > 0 { %s = &%s[0] }` tmp := p.tmpVar() return fmt.Sprintf(code, tmp, p.Type[2:], p.Name, tmp, p.Name) }
[ "func", "(", "p", "*", "Param", ")", "SliceTmpVarCode", "(", ")", "string", "{", "const", "code", "=", "`var %s *%s\n\tif len(%s) > 0 {\n\t\t%s = &%s[0]\n\t}`", "\n", "tmp", ":=", "p", ".", "tmpVar", "(", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "code", ",", "tmp", ",", "p", ".", "Type", "[", "2", ":", "]", ",", "p", ".", "Name", ",", "tmp", ",", "p", ".", "Name", ")", "\n", "}" ]
// SliceTmpVarCode returns source code for slice temp variable.
[ "SliceTmpVarCode", "returns", "source", "code", "for", "slice", "temp", "variable", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L121-L128
150,715
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
StringTmpVarCode
func (p *Param) StringTmpVarCode() string { errvar := p.fn.Rets.ErrorVarName() if errvar == "" { errvar = "_" } tmp := p.tmpVar() const code = `var %s %s %s, %s = %s(%s)` s := fmt.Sprintf(code, tmp, p.fn.StrconvType(), tmp, errvar, p.fn.StrconvFunc(), p.Name) if errvar == "-" { return s } const morecode = ` if %s != nil { return }` return s + fmt.Sprintf(morecode, errvar) }
go
func (p *Param) StringTmpVarCode() string { errvar := p.fn.Rets.ErrorVarName() if errvar == "" { errvar = "_" } tmp := p.tmpVar() const code = `var %s %s %s, %s = %s(%s)` s := fmt.Sprintf(code, tmp, p.fn.StrconvType(), tmp, errvar, p.fn.StrconvFunc(), p.Name) if errvar == "-" { return s } const morecode = ` if %s != nil { return }` return s + fmt.Sprintf(morecode, errvar) }
[ "func", "(", "p", "*", "Param", ")", "StringTmpVarCode", "(", ")", "string", "{", "errvar", ":=", "p", ".", "fn", ".", "Rets", ".", "ErrorVarName", "(", ")", "\n", "if", "errvar", "==", "\"", "\"", "{", "errvar", "=", "\"", "\"", "\n", "}", "\n", "tmp", ":=", "p", ".", "tmpVar", "(", ")", "\n", "const", "code", "=", "`var %s %s\n\t%s, %s = %s(%s)`", "\n", "s", ":=", "fmt", ".", "Sprintf", "(", "code", ",", "tmp", ",", "p", ".", "fn", ".", "StrconvType", "(", ")", ",", "tmp", ",", "errvar", ",", "p", ".", "fn", ".", "StrconvFunc", "(", ")", ",", "p", ".", "Name", ")", "\n", "if", "errvar", "==", "\"", "\"", "{", "return", "s", "\n", "}", "\n", "const", "morecode", "=", "`\n\tif %s != nil {\n\t\treturn\n\t}`", "\n", "return", "s", "+", "fmt", ".", "Sprintf", "(", "morecode", ",", "errvar", ")", "\n", "}" ]
// StringTmpVarCode returns source code for string temp variable.
[ "StringTmpVarCode", "returns", "source", "code", "for", "string", "temp", "variable", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L131-L148
150,716
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
TmpVarCode
func (p *Param) TmpVarCode() string { switch { case p.Type == "bool": return p.BoolTmpVarCode() case strings.HasPrefix(p.Type, "[]"): return p.SliceTmpVarCode() default: return "" } }
go
func (p *Param) TmpVarCode() string { switch { case p.Type == "bool": return p.BoolTmpVarCode() case strings.HasPrefix(p.Type, "[]"): return p.SliceTmpVarCode() default: return "" } }
[ "func", "(", "p", "*", "Param", ")", "TmpVarCode", "(", ")", "string", "{", "switch", "{", "case", "p", ".", "Type", "==", "\"", "\"", ":", "return", "p", ".", "BoolTmpVarCode", "(", ")", "\n", "case", "strings", ".", "HasPrefix", "(", "p", ".", "Type", ",", "\"", "\"", ")", ":", "return", "p", ".", "SliceTmpVarCode", "(", ")", "\n", "default", ":", "return", "\"", "\"", "\n", "}", "\n", "}" ]
// TmpVarCode returns source code for temp variable.
[ "TmpVarCode", "returns", "source", "code", "for", "temp", "variable", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L151-L160
150,717
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
HelperType
func (p *Param) HelperType() string { if p.Type == "string" { return p.fn.StrconvType() } return p.Type }
go
func (p *Param) HelperType() string { if p.Type == "string" { return p.fn.StrconvType() } return p.Type }
[ "func", "(", "p", "*", "Param", ")", "HelperType", "(", ")", "string", "{", "if", "p", ".", "Type", "==", "\"", "\"", "{", "return", "p", ".", "fn", ".", "StrconvType", "(", ")", "\n", "}", "\n", "return", "p", ".", "Type", "\n", "}" ]
// HelperType returns type of parameter p used in helper function.
[ "HelperType", "returns", "type", "of", "parameter", "p", "used", "in", "helper", "function", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L198-L203
150,718
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
join
func join(ps []*Param, fn func(*Param) string, sep string) string { if len(ps) == 0 { return "" } a := make([]string, 0) for _, p := range ps { a = append(a, fn(p)) } return strings.Join(a, sep) }
go
func join(ps []*Param, fn func(*Param) string, sep string) string { if len(ps) == 0 { return "" } a := make([]string, 0) for _, p := range ps { a = append(a, fn(p)) } return strings.Join(a, sep) }
[ "func", "join", "(", "ps", "[", "]", "*", "Param", ",", "fn", "func", "(", "*", "Param", ")", "string", ",", "sep", "string", ")", "string", "{", "if", "len", "(", "ps", ")", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "a", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "p", ":=", "range", "ps", "{", "a", "=", "append", "(", "a", ",", "fn", "(", "p", ")", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "a", ",", "sep", ")", "\n", "}" ]
// join concatenates parameters ps into a string with sep separator. // Each parameter is converted into string by applying fn to it // before conversion.
[ "join", "concatenates", "parameters", "ps", "into", "a", "string", "with", "sep", "separator", ".", "Each", "parameter", "is", "converted", "into", "string", "by", "applying", "fn", "to", "it", "before", "conversion", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L208-L217
150,719
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
ErrorVarName
func (r *Rets) ErrorVarName() string { if r.ReturnsError { return "err" } if r.Type == "error" { return r.Name } return "" }
go
func (r *Rets) ErrorVarName() string { if r.ReturnsError { return "err" } if r.Type == "error" { return r.Name } return "" }
[ "func", "(", "r", "*", "Rets", ")", "ErrorVarName", "(", ")", "string", "{", "if", "r", ".", "ReturnsError", "{", "return", "\"", "\"", "\n", "}", "\n", "if", "r", ".", "Type", "==", "\"", "\"", "{", "return", "r", ".", "Name", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// ErrorVarName returns error variable name for r.
[ "ErrorVarName", "returns", "error", "variable", "name", "for", "r", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L228-L236
150,720
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
List
func (r *Rets) List() string { s := join(r.ToParams(), func(p *Param) string { return p.Name + " " + p.Type }, ", ") if len(s) > 0 { s = "(" + s + ")" } return s }
go
func (r *Rets) List() string { s := join(r.ToParams(), func(p *Param) string { return p.Name + " " + p.Type }, ", ") if len(s) > 0 { s = "(" + s + ")" } return s }
[ "func", "(", "r", "*", "Rets", ")", "List", "(", ")", "string", "{", "s", ":=", "join", "(", "r", ".", "ToParams", "(", ")", ",", "func", "(", "p", "*", "Param", ")", "string", "{", "return", "p", ".", "Name", "+", "\"", "\"", "+", "p", ".", "Type", "}", ",", "\"", "\"", ")", "\n", "if", "len", "(", "s", ")", ">", "0", "{", "s", "=", "\"", "\"", "+", "s", "+", "\"", "\"", "\n", "}", "\n", "return", "s", "\n", "}" ]
// List returns source code of syscall return parameters.
[ "List", "returns", "source", "code", "of", "syscall", "return", "parameters", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L251-L257
150,721
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
PrintList
func (r *Rets) PrintList() string { return join(r.ToParams(), func(p *Param) string { return fmt.Sprintf(`"%s=", %s, `, p.Name, p.Name) }, `", ", `) }
go
func (r *Rets) PrintList() string { return join(r.ToParams(), func(p *Param) string { return fmt.Sprintf(`"%s=", %s, `, p.Name, p.Name) }, `", ", `) }
[ "func", "(", "r", "*", "Rets", ")", "PrintList", "(", ")", "string", "{", "return", "join", "(", "r", ".", "ToParams", "(", ")", ",", "func", "(", "p", "*", "Param", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "`\"%s=\", %s, `", ",", "p", ".", "Name", ",", "p", ".", "Name", ")", "}", ",", "`\", \", `", ")", "\n", "}" ]
// PrintList returns source code of trace printing part correspondent // to syscall return values.
[ "PrintList", "returns", "source", "code", "of", "trace", "printing", "part", "correspondent", "to", "syscall", "return", "values", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L261-L263
150,722
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
SetReturnValuesCode
func (r *Rets) SetReturnValuesCode() string { if r.Name == "" && !r.ReturnsError { return "" } retvar := "r0" if r.Name == "" { retvar = "r1" } errvar := "_" if r.ReturnsError { errvar = "e1" } return fmt.Sprintf("%s, _, %s := ", retvar, errvar) }
go
func (r *Rets) SetReturnValuesCode() string { if r.Name == "" && !r.ReturnsError { return "" } retvar := "r0" if r.Name == "" { retvar = "r1" } errvar := "_" if r.ReturnsError { errvar = "e1" } return fmt.Sprintf("%s, _, %s := ", retvar, errvar) }
[ "func", "(", "r", "*", "Rets", ")", "SetReturnValuesCode", "(", ")", "string", "{", "if", "r", ".", "Name", "==", "\"", "\"", "&&", "!", "r", ".", "ReturnsError", "{", "return", "\"", "\"", "\n", "}", "\n", "retvar", ":=", "\"", "\"", "\n", "if", "r", ".", "Name", "==", "\"", "\"", "{", "retvar", "=", "\"", "\"", "\n", "}", "\n", "errvar", ":=", "\"", "\"", "\n", "if", "r", ".", "ReturnsError", "{", "errvar", "=", "\"", "\"", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "retvar", ",", "errvar", ")", "\n", "}" ]
// SetReturnValuesCode returns source code that accepts syscall return values.
[ "SetReturnValuesCode", "returns", "source", "code", "that", "accepts", "syscall", "return", "values", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L266-L279
150,723
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
SetErrorCode
func (r *Rets) SetErrorCode() string { const code = `if r0 != 0 { %s = %sErrno(r0) }` if r.Name == "" && !r.ReturnsError { return "" } if r.Name == "" { return r.useLongHandleErrorCode("r1") } if r.Type == "error" { return fmt.Sprintf(code, r.Name, syscalldot()) } s := "" switch { case r.Type[0] == '*': s = fmt.Sprintf("%s = (%s)(unsafe.Pointer(r0))", r.Name, r.Type) case r.Type == "bool": s = fmt.Sprintf("%s = r0 != 0", r.Name) default: s = fmt.Sprintf("%s = %s(r0)", r.Name, r.Type) } if !r.ReturnsError { return s } return s + "\n\t" + r.useLongHandleErrorCode(r.Name) }
go
func (r *Rets) SetErrorCode() string { const code = `if r0 != 0 { %s = %sErrno(r0) }` if r.Name == "" && !r.ReturnsError { return "" } if r.Name == "" { return r.useLongHandleErrorCode("r1") } if r.Type == "error" { return fmt.Sprintf(code, r.Name, syscalldot()) } s := "" switch { case r.Type[0] == '*': s = fmt.Sprintf("%s = (%s)(unsafe.Pointer(r0))", r.Name, r.Type) case r.Type == "bool": s = fmt.Sprintf("%s = r0 != 0", r.Name) default: s = fmt.Sprintf("%s = %s(r0)", r.Name, r.Type) } if !r.ReturnsError { return s } return s + "\n\t" + r.useLongHandleErrorCode(r.Name) }
[ "func", "(", "r", "*", "Rets", ")", "SetErrorCode", "(", ")", "string", "{", "const", "code", "=", "`if r0 != 0 {\n\t\t%s = %sErrno(r0)\n\t}`", "\n", "if", "r", ".", "Name", "==", "\"", "\"", "&&", "!", "r", ".", "ReturnsError", "{", "return", "\"", "\"", "\n", "}", "\n", "if", "r", ".", "Name", "==", "\"", "\"", "{", "return", "r", ".", "useLongHandleErrorCode", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "r", ".", "Type", "==", "\"", "\"", "{", "return", "fmt", ".", "Sprintf", "(", "code", ",", "r", ".", "Name", ",", "syscalldot", "(", ")", ")", "\n", "}", "\n", "s", ":=", "\"", "\"", "\n", "switch", "{", "case", "r", ".", "Type", "[", "0", "]", "==", "'*'", ":", "s", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "r", ".", "Name", ",", "r", ".", "Type", ")", "\n", "case", "r", ".", "Type", "==", "\"", "\"", ":", "s", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "r", ".", "Name", ")", "\n", "default", ":", "s", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "r", ".", "Name", ",", "r", ".", "Type", ")", "\n", "}", "\n", "if", "!", "r", ".", "ReturnsError", "{", "return", "s", "\n", "}", "\n", "return", "s", "+", "\"", "\\n", "\\t", "\"", "+", "r", ".", "useLongHandleErrorCode", "(", "r", ".", "Name", ")", "\n", "}" ]
// SetErrorCode returns source code that sets return parameters.
[ "SetErrorCode", "returns", "source", "code", "that", "sets", "return", "parameters", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L297-L323
150,724
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
extractParams
func extractParams(s string, f *Fn) ([]*Param, error) { s = trim(s) if s == "" { return nil, nil } a := strings.Split(s, ",") ps := make([]*Param, len(a)) for i := range ps { s2 := trim(a[i]) b := strings.Split(s2, " ") if len(b) != 2 { b = strings.Split(s2, "\t") if len(b) != 2 { return nil, errors.New("Could not extract function parameter from \"" + s2 + "\"") } } ps[i] = &Param{ Name: trim(b[0]), Type: trim(b[1]), fn: f, tmpVarIdx: -1, } } return ps, nil }
go
func extractParams(s string, f *Fn) ([]*Param, error) { s = trim(s) if s == "" { return nil, nil } a := strings.Split(s, ",") ps := make([]*Param, len(a)) for i := range ps { s2 := trim(a[i]) b := strings.Split(s2, " ") if len(b) != 2 { b = strings.Split(s2, "\t") if len(b) != 2 { return nil, errors.New("Could not extract function parameter from \"" + s2 + "\"") } } ps[i] = &Param{ Name: trim(b[0]), Type: trim(b[1]), fn: f, tmpVarIdx: -1, } } return ps, nil }
[ "func", "extractParams", "(", "s", "string", ",", "f", "*", "Fn", ")", "(", "[", "]", "*", "Param", ",", "error", ")", "{", "s", "=", "trim", "(", "s", ")", "\n", "if", "s", "==", "\"", "\"", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "a", ":=", "strings", ".", "Split", "(", "s", ",", "\"", "\"", ")", "\n", "ps", ":=", "make", "(", "[", "]", "*", "Param", ",", "len", "(", "a", ")", ")", "\n", "for", "i", ":=", "range", "ps", "{", "s2", ":=", "trim", "(", "a", "[", "i", "]", ")", "\n", "b", ":=", "strings", ".", "Split", "(", "s2", ",", "\"", "\"", ")", "\n", "if", "len", "(", "b", ")", "!=", "2", "{", "b", "=", "strings", ".", "Split", "(", "s2", ",", "\"", "\\t", "\"", ")", "\n", "if", "len", "(", "b", ")", "!=", "2", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\\\"", "\"", "+", "s2", "+", "\"", "\\\"", "\"", ")", "\n", "}", "\n", "}", "\n", "ps", "[", "i", "]", "=", "&", "Param", "{", "Name", ":", "trim", "(", "b", "[", "0", "]", ")", ",", "Type", ":", "trim", "(", "b", "[", "1", "]", ")", ",", "fn", ":", "f", ",", "tmpVarIdx", ":", "-", "1", ",", "}", "\n", "}", "\n", "return", "ps", ",", "nil", "\n", "}" ]
// extractParams parses s to extract function parameters.
[ "extractParams", "parses", "s", "to", "extract", "function", "parameters", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L339-L363
150,725
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
extractSection
func extractSection(s string, start, end rune) (prefix, body, suffix string, found bool) { s = trim(s) if strings.HasPrefix(s, string(start)) { // no prefix body = s[1:] } else { a := strings.SplitN(s, string(start), 2) if len(a) != 2 { return "", "", s, false } prefix = a[0] body = a[1] } a := strings.SplitN(body, string(end), 2) if len(a) != 2 { return "", "", "", false } return prefix, a[0], a[1], true }
go
func extractSection(s string, start, end rune) (prefix, body, suffix string, found bool) { s = trim(s) if strings.HasPrefix(s, string(start)) { // no prefix body = s[1:] } else { a := strings.SplitN(s, string(start), 2) if len(a) != 2 { return "", "", s, false } prefix = a[0] body = a[1] } a := strings.SplitN(body, string(end), 2) if len(a) != 2 { return "", "", "", false } return prefix, a[0], a[1], true }
[ "func", "extractSection", "(", "s", "string", ",", "start", ",", "end", "rune", ")", "(", "prefix", ",", "body", ",", "suffix", "string", ",", "found", "bool", ")", "{", "s", "=", "trim", "(", "s", ")", "\n", "if", "strings", ".", "HasPrefix", "(", "s", ",", "string", "(", "start", ")", ")", "{", "// no prefix", "body", "=", "s", "[", "1", ":", "]", "\n", "}", "else", "{", "a", ":=", "strings", ".", "SplitN", "(", "s", ",", "string", "(", "start", ")", ",", "2", ")", "\n", "if", "len", "(", "a", ")", "!=", "2", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "s", ",", "false", "\n", "}", "\n", "prefix", "=", "a", "[", "0", "]", "\n", "body", "=", "a", "[", "1", "]", "\n", "}", "\n", "a", ":=", "strings", ".", "SplitN", "(", "body", ",", "string", "(", "end", ")", ",", "2", ")", "\n", "if", "len", "(", "a", ")", "!=", "2", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "false", "\n", "}", "\n", "return", "prefix", ",", "a", "[", "0", "]", ",", "a", "[", "1", "]", ",", "true", "\n", "}" ]
// extractSection extracts text out of string s starting after start // and ending just before end. found return value will indicate success, // and prefix, body and suffix will contain correspondent parts of string s.
[ "extractSection", "extracts", "text", "out", "of", "string", "s", "starting", "after", "start", "and", "ending", "just", "before", "end", ".", "found", "return", "value", "will", "indicate", "success", "and", "prefix", "body", "and", "suffix", "will", "contain", "correspondent", "parts", "of", "string", "s", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L368-L386
150,726
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
newFn
func newFn(s string) (*Fn, error) { s = trim(s) f := &Fn{ Rets: &Rets{}, src: s, PrintTrace: *printTraceFlag, } // function name and args prefix, body, s, found := extractSection(s, '(', ')') if !found || prefix == "" { return nil, errors.New("Could not extract function name and parameters from \"" + f.src + "\"") } f.Name = prefix var err error f.Params, err = extractParams(body, f) if err != nil { return nil, err } // return values _, body, s, found = extractSection(s, '(', ')') if found { r, err := extractParams(body, f) if err != nil { return nil, err } switch len(r) { case 0: case 1: if r[0].IsError() { f.Rets.ReturnsError = true } else { f.Rets.Name = r[0].Name f.Rets.Type = r[0].Type } case 2: if !r[1].IsError() { return nil, errors.New("Only last windows error is allowed as second return value in \"" + f.src + "\"") } f.Rets.ReturnsError = true f.Rets.Name = r[0].Name f.Rets.Type = r[0].Type default: return nil, errors.New("Too many return values in \"" + f.src + "\"") } } // fail condition _, body, s, found = extractSection(s, '[', ']') if found { f.Rets.FailCond = body } // dll and dll function names s = trim(s) if s == "" { return f, nil } if !strings.HasPrefix(s, "=") { return nil, errors.New("Could not extract dll name from \"" + f.src + "\"") } s = trim(s[1:]) a := strings.Split(s, ".") switch len(a) { case 1: f.dllfuncname = a[0] case 2: f.dllname = a[0] f.dllfuncname = a[1] default: return nil, errors.New("Could not extract dll name from \"" + f.src + "\"") } return f, nil }
go
func newFn(s string) (*Fn, error) { s = trim(s) f := &Fn{ Rets: &Rets{}, src: s, PrintTrace: *printTraceFlag, } // function name and args prefix, body, s, found := extractSection(s, '(', ')') if !found || prefix == "" { return nil, errors.New("Could not extract function name and parameters from \"" + f.src + "\"") } f.Name = prefix var err error f.Params, err = extractParams(body, f) if err != nil { return nil, err } // return values _, body, s, found = extractSection(s, '(', ')') if found { r, err := extractParams(body, f) if err != nil { return nil, err } switch len(r) { case 0: case 1: if r[0].IsError() { f.Rets.ReturnsError = true } else { f.Rets.Name = r[0].Name f.Rets.Type = r[0].Type } case 2: if !r[1].IsError() { return nil, errors.New("Only last windows error is allowed as second return value in \"" + f.src + "\"") } f.Rets.ReturnsError = true f.Rets.Name = r[0].Name f.Rets.Type = r[0].Type default: return nil, errors.New("Too many return values in \"" + f.src + "\"") } } // fail condition _, body, s, found = extractSection(s, '[', ']') if found { f.Rets.FailCond = body } // dll and dll function names s = trim(s) if s == "" { return f, nil } if !strings.HasPrefix(s, "=") { return nil, errors.New("Could not extract dll name from \"" + f.src + "\"") } s = trim(s[1:]) a := strings.Split(s, ".") switch len(a) { case 1: f.dllfuncname = a[0] case 2: f.dllname = a[0] f.dllfuncname = a[1] default: return nil, errors.New("Could not extract dll name from \"" + f.src + "\"") } return f, nil }
[ "func", "newFn", "(", "s", "string", ")", "(", "*", "Fn", ",", "error", ")", "{", "s", "=", "trim", "(", "s", ")", "\n", "f", ":=", "&", "Fn", "{", "Rets", ":", "&", "Rets", "{", "}", ",", "src", ":", "s", ",", "PrintTrace", ":", "*", "printTraceFlag", ",", "}", "\n", "// function name and args", "prefix", ",", "body", ",", "s", ",", "found", ":=", "extractSection", "(", "s", ",", "'('", ",", "')'", ")", "\n", "if", "!", "found", "||", "prefix", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\\\"", "\"", "+", "f", ".", "src", "+", "\"", "\\\"", "\"", ")", "\n", "}", "\n", "f", ".", "Name", "=", "prefix", "\n", "var", "err", "error", "\n", "f", ".", "Params", ",", "err", "=", "extractParams", "(", "body", ",", "f", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "// return values", "_", ",", "body", ",", "s", ",", "found", "=", "extractSection", "(", "s", ",", "'('", ",", "')'", ")", "\n", "if", "found", "{", "r", ",", "err", ":=", "extractParams", "(", "body", ",", "f", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "switch", "len", "(", "r", ")", "{", "case", "0", ":", "case", "1", ":", "if", "r", "[", "0", "]", ".", "IsError", "(", ")", "{", "f", ".", "Rets", ".", "ReturnsError", "=", "true", "\n", "}", "else", "{", "f", ".", "Rets", ".", "Name", "=", "r", "[", "0", "]", ".", "Name", "\n", "f", ".", "Rets", ".", "Type", "=", "r", "[", "0", "]", ".", "Type", "\n", "}", "\n", "case", "2", ":", "if", "!", "r", "[", "1", "]", ".", "IsError", "(", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\\\"", "\"", "+", "f", ".", "src", "+", "\"", "\\\"", "\"", ")", "\n", "}", "\n", "f", ".", "Rets", ".", "ReturnsError", "=", "true", "\n", "f", ".", "Rets", ".", "Name", "=", "r", "[", "0", "]", ".", "Name", "\n", "f", ".", "Rets", ".", "Type", "=", "r", "[", "0", "]", ".", "Type", "\n", "default", ":", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\\\"", "\"", "+", "f", ".", "src", "+", "\"", "\\\"", "\"", ")", "\n", "}", "\n", "}", "\n", "// fail condition", "_", ",", "body", ",", "s", ",", "found", "=", "extractSection", "(", "s", ",", "'['", ",", "']'", ")", "\n", "if", "found", "{", "f", ".", "Rets", ".", "FailCond", "=", "body", "\n", "}", "\n", "// dll and dll function names", "s", "=", "trim", "(", "s", ")", "\n", "if", "s", "==", "\"", "\"", "{", "return", "f", ",", "nil", "\n", "}", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "s", ",", "\"", "\"", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\\\"", "\"", "+", "f", ".", "src", "+", "\"", "\\\"", "\"", ")", "\n", "}", "\n", "s", "=", "trim", "(", "s", "[", "1", ":", "]", ")", "\n", "a", ":=", "strings", ".", "Split", "(", "s", ",", "\"", "\"", ")", "\n", "switch", "len", "(", "a", ")", "{", "case", "1", ":", "f", ".", "dllfuncname", "=", "a", "[", "0", "]", "\n", "case", "2", ":", "f", ".", "dllname", "=", "a", "[", "0", "]", "\n", "f", ".", "dllfuncname", "=", "a", "[", "1", "]", "\n", "default", ":", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\\\"", "\"", "+", "f", ".", "src", "+", "\"", "\\\"", "\"", ")", "\n", "}", "\n", "return", "f", ",", "nil", "\n", "}" ]
// newFn parses string s and return created function Fn.
[ "newFn", "parses", "string", "s", "and", "return", "created", "function", "Fn", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L389-L459
150,727
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
DLLFuncName
func (f *Fn) DLLFuncName() string { if f.dllfuncname == "" { return f.Name } return f.dllfuncname }
go
func (f *Fn) DLLFuncName() string { if f.dllfuncname == "" { return f.Name } return f.dllfuncname }
[ "func", "(", "f", "*", "Fn", ")", "DLLFuncName", "(", ")", "string", "{", "if", "f", ".", "dllfuncname", "==", "\"", "\"", "{", "return", "f", ".", "Name", "\n", "}", "\n", "return", "f", ".", "dllfuncname", "\n", "}" ]
// DLLName returns DLL function name for function f.
[ "DLLName", "returns", "DLL", "function", "name", "for", "function", "f", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L470-L475
150,728
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
ParamList
func (f *Fn) ParamList() string { return join(f.Params, func(p *Param) string { return p.Name + " " + p.Type }, ", ") }
go
func (f *Fn) ParamList() string { return join(f.Params, func(p *Param) string { return p.Name + " " + p.Type }, ", ") }
[ "func", "(", "f", "*", "Fn", ")", "ParamList", "(", ")", "string", "{", "return", "join", "(", "f", ".", "Params", ",", "func", "(", "p", "*", "Param", ")", "string", "{", "return", "p", ".", "Name", "+", "\"", "\"", "+", "p", ".", "Type", "}", ",", "\"", "\"", ")", "\n", "}" ]
// ParamList returns source code for function f parameters.
[ "ParamList", "returns", "source", "code", "for", "function", "f", "parameters", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L478-L480
150,729
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
HelperParamList
func (f *Fn) HelperParamList() string { return join(f.Params, func(p *Param) string { return p.Name + " " + p.HelperType() }, ", ") }
go
func (f *Fn) HelperParamList() string { return join(f.Params, func(p *Param) string { return p.Name + " " + p.HelperType() }, ", ") }
[ "func", "(", "f", "*", "Fn", ")", "HelperParamList", "(", ")", "string", "{", "return", "join", "(", "f", ".", "Params", ",", "func", "(", "p", "*", "Param", ")", "string", "{", "return", "p", ".", "Name", "+", "\"", "\"", "+", "p", ".", "HelperType", "(", ")", "}", ",", "\"", "\"", ")", "\n", "}" ]
// HelperParamList returns source code for helper function f parameters.
[ "HelperParamList", "returns", "source", "code", "for", "helper", "function", "f", "parameters", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L483-L485
150,730
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
ParamPrintList
func (f *Fn) ParamPrintList() string { return join(f.Params, func(p *Param) string { return fmt.Sprintf(`"%s=", %s, `, p.Name, p.Name) }, `", ", `) }
go
func (f *Fn) ParamPrintList() string { return join(f.Params, func(p *Param) string { return fmt.Sprintf(`"%s=", %s, `, p.Name, p.Name) }, `", ", `) }
[ "func", "(", "f", "*", "Fn", ")", "ParamPrintList", "(", ")", "string", "{", "return", "join", "(", "f", ".", "Params", ",", "func", "(", "p", "*", "Param", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "`\"%s=\", %s, `", ",", "p", ".", "Name", ",", "p", ".", "Name", ")", "}", ",", "`\", \", `", ")", "\n", "}" ]
// ParamPrintList returns source code of trace printing part correspondent // to syscall input parameters.
[ "ParamPrintList", "returns", "source", "code", "of", "trace", "printing", "part", "correspondent", "to", "syscall", "input", "parameters", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L489-L491
150,731
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
ParamCount
func (f *Fn) ParamCount() int { n := 0 for _, p := range f.Params { n += len(p.SyscallArgList()) } return n }
go
func (f *Fn) ParamCount() int { n := 0 for _, p := range f.Params { n += len(p.SyscallArgList()) } return n }
[ "func", "(", "f", "*", "Fn", ")", "ParamCount", "(", ")", "int", "{", "n", ":=", "0", "\n", "for", "_", ",", "p", ":=", "range", "f", ".", "Params", "{", "n", "+=", "len", "(", "p", ".", "SyscallArgList", "(", ")", ")", "\n", "}", "\n", "return", "n", "\n", "}" ]
// ParamCount return number of syscall parameters for function f.
[ "ParamCount", "return", "number", "of", "syscall", "parameters", "for", "function", "f", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L494-L500
150,732
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
Syscall
func (f *Fn) Syscall() string { c := f.SyscallParamCount() if c == 3 { return syscalldot() + "Syscall" } return syscalldot() + "Syscall" + strconv.Itoa(c) }
go
func (f *Fn) Syscall() string { c := f.SyscallParamCount() if c == 3 { return syscalldot() + "Syscall" } return syscalldot() + "Syscall" + strconv.Itoa(c) }
[ "func", "(", "f", "*", "Fn", ")", "Syscall", "(", ")", "string", "{", "c", ":=", "f", ".", "SyscallParamCount", "(", ")", "\n", "if", "c", "==", "3", "{", "return", "syscalldot", "(", ")", "+", "\"", "\"", "\n", "}", "\n", "return", "syscalldot", "(", ")", "+", "\"", "\"", "+", "strconv", ".", "Itoa", "(", "c", ")", "\n", "}" ]
// Syscall determines which SyscallX function to use for function f.
[ "Syscall", "determines", "which", "SyscallX", "function", "to", "use", "for", "function", "f", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L523-L529
150,733
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
SyscallParamList
func (f *Fn) SyscallParamList() string { a := make([]string, 0) for _, p := range f.Params { a = append(a, p.SyscallArgList()...) } for len(a) < f.SyscallParamCount() { a = append(a, "0") } return strings.Join(a, ", ") }
go
func (f *Fn) SyscallParamList() string { a := make([]string, 0) for _, p := range f.Params { a = append(a, p.SyscallArgList()...) } for len(a) < f.SyscallParamCount() { a = append(a, "0") } return strings.Join(a, ", ") }
[ "func", "(", "f", "*", "Fn", ")", "SyscallParamList", "(", ")", "string", "{", "a", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "p", ":=", "range", "f", ".", "Params", "{", "a", "=", "append", "(", "a", ",", "p", ".", "SyscallArgList", "(", ")", "...", ")", "\n", "}", "\n", "for", "len", "(", "a", ")", "<", "f", ".", "SyscallParamCount", "(", ")", "{", "a", "=", "append", "(", "a", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "a", ",", "\"", "\"", ")", "\n", "}" ]
// SyscallParamList returns source code for SyscallX parameters for function f.
[ "SyscallParamList", "returns", "source", "code", "for", "SyscallX", "parameters", "for", "function", "f", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L532-L541
150,734
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
HelperCallParamList
func (f *Fn) HelperCallParamList() string { a := make([]string, 0, len(f.Params)) for _, p := range f.Params { s := p.Name if p.Type == "string" { s = p.tmpVar() } a = append(a, s) } return strings.Join(a, ", ") }
go
func (f *Fn) HelperCallParamList() string { a := make([]string, 0, len(f.Params)) for _, p := range f.Params { s := p.Name if p.Type == "string" { s = p.tmpVar() } a = append(a, s) } return strings.Join(a, ", ") }
[ "func", "(", "f", "*", "Fn", ")", "HelperCallParamList", "(", ")", "string", "{", "a", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "f", ".", "Params", ")", ")", "\n", "for", "_", ",", "p", ":=", "range", "f", ".", "Params", "{", "s", ":=", "p", ".", "Name", "\n", "if", "p", ".", "Type", "==", "\"", "\"", "{", "s", "=", "p", ".", "tmpVar", "(", ")", "\n", "}", "\n", "a", "=", "append", "(", "a", ",", "s", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "a", ",", "\"", "\"", ")", "\n", "}" ]
// HelperCallParamList returns source code of call into function f helper.
[ "HelperCallParamList", "returns", "source", "code", "of", "call", "into", "function", "f", "helper", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L544-L554
150,735
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
HasStringParam
func (f *Fn) HasStringParam() bool { for _, p := range f.Params { if p.Type == "string" { return true } } return false }
go
func (f *Fn) HasStringParam() bool { for _, p := range f.Params { if p.Type == "string" { return true } } return false }
[ "func", "(", "f", "*", "Fn", ")", "HasStringParam", "(", ")", "bool", "{", "for", "_", ",", "p", ":=", "range", "f", ".", "Params", "{", "if", "p", ".", "Type", "==", "\"", "\"", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// HasStringParam is true, if f has at least one string parameter. // Otherwise it is false.
[ "HasStringParam", "is", "true", "if", "f", "has", "at", "least", "one", "string", "parameter", ".", "Otherwise", "it", "is", "false", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L581-L588
150,736
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
HelperName
func (f *Fn) HelperName() string { if !f.HasStringParam() { return f.Name } return "_" + f.Name }
go
func (f *Fn) HelperName() string { if !f.HasStringParam() { return f.Name } return "_" + f.Name }
[ "func", "(", "f", "*", "Fn", ")", "HelperName", "(", ")", "string", "{", "if", "!", "f", ".", "HasStringParam", "(", ")", "{", "return", "f", ".", "Name", "\n", "}", "\n", "return", "\"", "\"", "+", "f", ".", "Name", "\n", "}" ]
// HelperName returns name of function f helper.
[ "HelperName", "returns", "name", "of", "function", "f", "helper", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L591-L596
150,737
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
DLLs
func (src *Source) DLLs() []string { uniq := make(map[string]bool) r := make([]string, 0) for _, f := range src.Funcs { name := f.DLLName() if _, found := uniq[name]; !found { uniq[name] = true r = append(r, name) } } return r }
go
func (src *Source) DLLs() []string { uniq := make(map[string]bool) r := make([]string, 0) for _, f := range src.Funcs { name := f.DLLName() if _, found := uniq[name]; !found { uniq[name] = true r = append(r, name) } } return r }
[ "func", "(", "src", "*", "Source", ")", "DLLs", "(", ")", "[", "]", "string", "{", "uniq", ":=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n", "r", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "f", ":=", "range", "src", ".", "Funcs", "{", "name", ":=", "f", ".", "DLLName", "(", ")", "\n", "if", "_", ",", "found", ":=", "uniq", "[", "name", "]", ";", "!", "found", "{", "uniq", "[", "name", "]", "=", "true", "\n", "r", "=", "append", "(", "r", ",", "name", ")", "\n", "}", "\n", "}", "\n", "return", "r", "\n", "}" ]
// DLLs return dll names for a source set src.
[ "DLLs", "return", "dll", "names", "for", "a", "source", "set", "src", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L650-L661
150,738
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
ParseFile
func (src *Source) ParseFile(path string) error { file, err := os.Open(path) if err != nil { return err } defer file.Close() s := bufio.NewScanner(file) for s.Scan() { t := trim(s.Text()) if len(t) < 7 { continue } if !strings.HasPrefix(t, "//sys") { continue } t = t[5:] if !(t[0] == ' ' || t[0] == '\t') { continue } f, err := newFn(t[1:]) if err != nil { return err } src.Funcs = append(src.Funcs, f) } if err := s.Err(); err != nil { return err } src.Files = append(src.Files, path) // get package name fset := token.NewFileSet() _, err = file.Seek(0, 0) if err != nil { return err } pkg, err := parser.ParseFile(fset, "", file, parser.PackageClauseOnly) if err != nil { return err } packageName = pkg.Name.Name return nil }
go
func (src *Source) ParseFile(path string) error { file, err := os.Open(path) if err != nil { return err } defer file.Close() s := bufio.NewScanner(file) for s.Scan() { t := trim(s.Text()) if len(t) < 7 { continue } if !strings.HasPrefix(t, "//sys") { continue } t = t[5:] if !(t[0] == ' ' || t[0] == '\t') { continue } f, err := newFn(t[1:]) if err != nil { return err } src.Funcs = append(src.Funcs, f) } if err := s.Err(); err != nil { return err } src.Files = append(src.Files, path) // get package name fset := token.NewFileSet() _, err = file.Seek(0, 0) if err != nil { return err } pkg, err := parser.ParseFile(fset, "", file, parser.PackageClauseOnly) if err != nil { return err } packageName = pkg.Name.Name return nil }
[ "func", "(", "src", "*", "Source", ")", "ParseFile", "(", "path", "string", ")", "error", "{", "file", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "file", ".", "Close", "(", ")", "\n\n", "s", ":=", "bufio", ".", "NewScanner", "(", "file", ")", "\n", "for", "s", ".", "Scan", "(", ")", "{", "t", ":=", "trim", "(", "s", ".", "Text", "(", ")", ")", "\n", "if", "len", "(", "t", ")", "<", "7", "{", "continue", "\n", "}", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "t", ",", "\"", "\"", ")", "{", "continue", "\n", "}", "\n", "t", "=", "t", "[", "5", ":", "]", "\n", "if", "!", "(", "t", "[", "0", "]", "==", "' '", "||", "t", "[", "0", "]", "==", "'\\t'", ")", "{", "continue", "\n", "}", "\n", "f", ",", "err", ":=", "newFn", "(", "t", "[", "1", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "src", ".", "Funcs", "=", "append", "(", "src", ".", "Funcs", ",", "f", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Err", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "src", ".", "Files", "=", "append", "(", "src", ".", "Files", ",", "path", ")", "\n\n", "// get package name", "fset", ":=", "token", ".", "NewFileSet", "(", ")", "\n", "_", ",", "err", "=", "file", ".", "Seek", "(", "0", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "pkg", ",", "err", ":=", "parser", ".", "ParseFile", "(", "fset", ",", "\"", "\"", ",", "file", ",", "parser", ".", "PackageClauseOnly", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "packageName", "=", "pkg", ".", "Name", ".", "Name", "\n\n", "return", "nil", "\n", "}" ]
// ParseFile adds additional file path to a source set src.
[ "ParseFile", "adds", "additional", "file", "path", "to", "a", "source", "set", "src", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L664-L708
150,739
Microsoft/go-winio
pkg/etw/mksyscall_windows.go
IsStdRepo
func (src *Source) IsStdRepo() (bool, error) { if len(src.Files) == 0 { return false, errors.New("no input files provided") } abspath, err := filepath.Abs(src.Files[0]) if err != nil { return false, err } goroot := runtime.GOROOT() if runtime.GOOS == "windows" { abspath = strings.ToLower(abspath) goroot = strings.ToLower(goroot) } sep := string(os.PathSeparator) if !strings.HasSuffix(goroot, sep) { goroot += sep } return strings.HasPrefix(abspath, goroot), nil }
go
func (src *Source) IsStdRepo() (bool, error) { if len(src.Files) == 0 { return false, errors.New("no input files provided") } abspath, err := filepath.Abs(src.Files[0]) if err != nil { return false, err } goroot := runtime.GOROOT() if runtime.GOOS == "windows" { abspath = strings.ToLower(abspath) goroot = strings.ToLower(goroot) } sep := string(os.PathSeparator) if !strings.HasSuffix(goroot, sep) { goroot += sep } return strings.HasPrefix(abspath, goroot), nil }
[ "func", "(", "src", "*", "Source", ")", "IsStdRepo", "(", ")", "(", "bool", ",", "error", ")", "{", "if", "len", "(", "src", ".", "Files", ")", "==", "0", "{", "return", "false", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "abspath", ",", "err", ":=", "filepath", ".", "Abs", "(", "src", ".", "Files", "[", "0", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "goroot", ":=", "runtime", ".", "GOROOT", "(", ")", "\n", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "{", "abspath", "=", "strings", ".", "ToLower", "(", "abspath", ")", "\n", "goroot", "=", "strings", ".", "ToLower", "(", "goroot", ")", "\n", "}", "\n", "sep", ":=", "string", "(", "os", ".", "PathSeparator", ")", "\n", "if", "!", "strings", ".", "HasSuffix", "(", "goroot", ",", "sep", ")", "{", "goroot", "+=", "sep", "\n", "}", "\n", "return", "strings", ".", "HasPrefix", "(", "abspath", ",", "goroot", ")", ",", "nil", "\n", "}" ]
// IsStdRepo reports whether src is part of standard library.
[ "IsStdRepo", "reports", "whether", "src", "is", "part", "of", "standard", "library", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/mksyscall_windows.go#L711-L729
150,740
Microsoft/go-winio
file.go
makeWin32File
func makeWin32File(h syscall.Handle) (*win32File, error) { f := &win32File{handle: h} ioInitOnce.Do(initIo) _, err := createIoCompletionPort(h, ioCompletionPort, 0, 0xffffffff) if err != nil { return nil, err } err = setFileCompletionNotificationModes(h, cFILE_SKIP_COMPLETION_PORT_ON_SUCCESS|cFILE_SKIP_SET_EVENT_ON_HANDLE) if err != nil { return nil, err } f.readDeadline.channel = make(timeoutChan) f.writeDeadline.channel = make(timeoutChan) return f, nil }
go
func makeWin32File(h syscall.Handle) (*win32File, error) { f := &win32File{handle: h} ioInitOnce.Do(initIo) _, err := createIoCompletionPort(h, ioCompletionPort, 0, 0xffffffff) if err != nil { return nil, err } err = setFileCompletionNotificationModes(h, cFILE_SKIP_COMPLETION_PORT_ON_SUCCESS|cFILE_SKIP_SET_EVENT_ON_HANDLE) if err != nil { return nil, err } f.readDeadline.channel = make(timeoutChan) f.writeDeadline.channel = make(timeoutChan) return f, nil }
[ "func", "makeWin32File", "(", "h", "syscall", ".", "Handle", ")", "(", "*", "win32File", ",", "error", ")", "{", "f", ":=", "&", "win32File", "{", "handle", ":", "h", "}", "\n", "ioInitOnce", ".", "Do", "(", "initIo", ")", "\n", "_", ",", "err", ":=", "createIoCompletionPort", "(", "h", ",", "ioCompletionPort", ",", "0", ",", "0xffffffff", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "err", "=", "setFileCompletionNotificationModes", "(", "h", ",", "cFILE_SKIP_COMPLETION_PORT_ON_SUCCESS", "|", "cFILE_SKIP_SET_EVENT_ON_HANDLE", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "f", ".", "readDeadline", ".", "channel", "=", "make", "(", "timeoutChan", ")", "\n", "f", ".", "writeDeadline", ".", "channel", "=", "make", "(", "timeoutChan", ")", "\n", "return", "f", ",", "nil", "\n", "}" ]
// makeWin32File makes a new win32File from an existing file handle
[ "makeWin32File", "makes", "a", "new", "win32File", "from", "an", "existing", "file", "handle" ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/file.go#L97-L111
150,741
Microsoft/go-winio
file.go
closeHandle
func (f *win32File) closeHandle() { f.wgLock.Lock() // Atomically set that we are closing, releasing the resources only once. if !f.closing.swap(true) { f.wgLock.Unlock() // cancel all IO and wait for it to complete cancelIoEx(f.handle, nil) f.wg.Wait() // at this point, no new IO can start syscall.Close(f.handle) f.handle = 0 } else { f.wgLock.Unlock() } }
go
func (f *win32File) closeHandle() { f.wgLock.Lock() // Atomically set that we are closing, releasing the resources only once. if !f.closing.swap(true) { f.wgLock.Unlock() // cancel all IO and wait for it to complete cancelIoEx(f.handle, nil) f.wg.Wait() // at this point, no new IO can start syscall.Close(f.handle) f.handle = 0 } else { f.wgLock.Unlock() } }
[ "func", "(", "f", "*", "win32File", ")", "closeHandle", "(", ")", "{", "f", ".", "wgLock", ".", "Lock", "(", ")", "\n", "// Atomically set that we are closing, releasing the resources only once.", "if", "!", "f", ".", "closing", ".", "swap", "(", "true", ")", "{", "f", ".", "wgLock", ".", "Unlock", "(", ")", "\n", "// cancel all IO and wait for it to complete", "cancelIoEx", "(", "f", ".", "handle", ",", "nil", ")", "\n", "f", ".", "wg", ".", "Wait", "(", ")", "\n", "// at this point, no new IO can start", "syscall", ".", "Close", "(", "f", ".", "handle", ")", "\n", "f", ".", "handle", "=", "0", "\n", "}", "else", "{", "f", ".", "wgLock", ".", "Unlock", "(", ")", "\n", "}", "\n", "}" ]
// closeHandle closes the resources associated with a Win32 handle
[ "closeHandle", "closes", "the", "resources", "associated", "with", "a", "Win32", "handle" ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/file.go#L118-L132
150,742
Microsoft/go-winio
file.go
ioCompletionProcessor
func ioCompletionProcessor(h syscall.Handle) { for { var bytes uint32 var key uintptr var op *ioOperation err := getQueuedCompletionStatus(h, &bytes, &key, &op, syscall.INFINITE) if op == nil { panic(err) } op.ch <- ioResult{bytes, err} } }
go
func ioCompletionProcessor(h syscall.Handle) { for { var bytes uint32 var key uintptr var op *ioOperation err := getQueuedCompletionStatus(h, &bytes, &key, &op, syscall.INFINITE) if op == nil { panic(err) } op.ch <- ioResult{bytes, err} } }
[ "func", "ioCompletionProcessor", "(", "h", "syscall", ".", "Handle", ")", "{", "for", "{", "var", "bytes", "uint32", "\n", "var", "key", "uintptr", "\n", "var", "op", "*", "ioOperation", "\n", "err", ":=", "getQueuedCompletionStatus", "(", "h", ",", "&", "bytes", ",", "&", "key", ",", "&", "op", ",", "syscall", ".", "INFINITE", ")", "\n", "if", "op", "==", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "op", ".", "ch", "<-", "ioResult", "{", "bytes", ",", "err", "}", "\n", "}", "\n", "}" ]
// ioCompletionProcessor processes completed async IOs forever
[ "ioCompletionProcessor", "processes", "completed", "async", "IOs", "forever" ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/file.go#L156-L167
150,743
Microsoft/go-winio
file.go
asyncIo
func (f *win32File) asyncIo(c *ioOperation, d *deadlineHandler, bytes uint32, err error) (int, error) { if err != syscall.ERROR_IO_PENDING { return int(bytes), err } if f.closing.isSet() { cancelIoEx(f.handle, &c.o) } var timeout timeoutChan if d != nil { d.channelLock.Lock() timeout = d.channel d.channelLock.Unlock() } var r ioResult select { case r = <-c.ch: err = r.err if err == syscall.ERROR_OPERATION_ABORTED { if f.closing.isSet() { err = ErrFileClosed } } else if err != nil && f.socket { // err is from Win32. Query the overlapped structure to get the winsock error. var bytes, flags uint32 err = wsaGetOverlappedResult(f.handle, &c.o, &bytes, false, &flags) } case <-timeout: cancelIoEx(f.handle, &c.o) r = <-c.ch err = r.err if err == syscall.ERROR_OPERATION_ABORTED { err = ErrTimeout } } // runtime.KeepAlive is needed, as c is passed via native // code to ioCompletionProcessor, c must remain alive // until the channel read is complete. runtime.KeepAlive(c) return int(r.bytes), err }
go
func (f *win32File) asyncIo(c *ioOperation, d *deadlineHandler, bytes uint32, err error) (int, error) { if err != syscall.ERROR_IO_PENDING { return int(bytes), err } if f.closing.isSet() { cancelIoEx(f.handle, &c.o) } var timeout timeoutChan if d != nil { d.channelLock.Lock() timeout = d.channel d.channelLock.Unlock() } var r ioResult select { case r = <-c.ch: err = r.err if err == syscall.ERROR_OPERATION_ABORTED { if f.closing.isSet() { err = ErrFileClosed } } else if err != nil && f.socket { // err is from Win32. Query the overlapped structure to get the winsock error. var bytes, flags uint32 err = wsaGetOverlappedResult(f.handle, &c.o, &bytes, false, &flags) } case <-timeout: cancelIoEx(f.handle, &c.o) r = <-c.ch err = r.err if err == syscall.ERROR_OPERATION_ABORTED { err = ErrTimeout } } // runtime.KeepAlive is needed, as c is passed via native // code to ioCompletionProcessor, c must remain alive // until the channel read is complete. runtime.KeepAlive(c) return int(r.bytes), err }
[ "func", "(", "f", "*", "win32File", ")", "asyncIo", "(", "c", "*", "ioOperation", ",", "d", "*", "deadlineHandler", ",", "bytes", "uint32", ",", "err", "error", ")", "(", "int", ",", "error", ")", "{", "if", "err", "!=", "syscall", ".", "ERROR_IO_PENDING", "{", "return", "int", "(", "bytes", ")", ",", "err", "\n", "}", "\n\n", "if", "f", ".", "closing", ".", "isSet", "(", ")", "{", "cancelIoEx", "(", "f", ".", "handle", ",", "&", "c", ".", "o", ")", "\n", "}", "\n\n", "var", "timeout", "timeoutChan", "\n", "if", "d", "!=", "nil", "{", "d", ".", "channelLock", ".", "Lock", "(", ")", "\n", "timeout", "=", "d", ".", "channel", "\n", "d", ".", "channelLock", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "var", "r", "ioResult", "\n", "select", "{", "case", "r", "=", "<-", "c", ".", "ch", ":", "err", "=", "r", ".", "err", "\n", "if", "err", "==", "syscall", ".", "ERROR_OPERATION_ABORTED", "{", "if", "f", ".", "closing", ".", "isSet", "(", ")", "{", "err", "=", "ErrFileClosed", "\n", "}", "\n", "}", "else", "if", "err", "!=", "nil", "&&", "f", ".", "socket", "{", "// err is from Win32. Query the overlapped structure to get the winsock error.", "var", "bytes", ",", "flags", "uint32", "\n", "err", "=", "wsaGetOverlappedResult", "(", "f", ".", "handle", ",", "&", "c", ".", "o", ",", "&", "bytes", ",", "false", ",", "&", "flags", ")", "\n", "}", "\n", "case", "<-", "timeout", ":", "cancelIoEx", "(", "f", ".", "handle", ",", "&", "c", ".", "o", ")", "\n", "r", "=", "<-", "c", ".", "ch", "\n", "err", "=", "r", ".", "err", "\n", "if", "err", "==", "syscall", ".", "ERROR_OPERATION_ABORTED", "{", "err", "=", "ErrTimeout", "\n", "}", "\n", "}", "\n\n", "// runtime.KeepAlive is needed, as c is passed via native", "// code to ioCompletionProcessor, c must remain alive", "// until the channel read is complete.", "runtime", ".", "KeepAlive", "(", "c", ")", "\n", "return", "int", "(", "r", ".", "bytes", ")", ",", "err", "\n", "}" ]
// asyncIo processes the return value from ReadFile or WriteFile, blocking until // the operation has actually completed.
[ "asyncIo", "processes", "the", "return", "value", "from", "ReadFile", "or", "WriteFile", "blocking", "until", "the", "operation", "has", "actually", "completed", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/file.go#L171-L214
150,744
Microsoft/go-winio
file.go
Read
func (f *win32File) Read(b []byte) (int, error) { c, err := f.prepareIo() if err != nil { return 0, err } defer f.wg.Done() if f.readDeadline.timedout.isSet() { return 0, ErrTimeout } var bytes uint32 err = syscall.ReadFile(f.handle, b, &bytes, &c.o) n, err := f.asyncIo(c, &f.readDeadline, bytes, err) runtime.KeepAlive(b) // Handle EOF conditions. if err == nil && n == 0 && len(b) != 0 { return 0, io.EOF } else if err == syscall.ERROR_BROKEN_PIPE { return 0, io.EOF } else { return n, err } }
go
func (f *win32File) Read(b []byte) (int, error) { c, err := f.prepareIo() if err != nil { return 0, err } defer f.wg.Done() if f.readDeadline.timedout.isSet() { return 0, ErrTimeout } var bytes uint32 err = syscall.ReadFile(f.handle, b, &bytes, &c.o) n, err := f.asyncIo(c, &f.readDeadline, bytes, err) runtime.KeepAlive(b) // Handle EOF conditions. if err == nil && n == 0 && len(b) != 0 { return 0, io.EOF } else if err == syscall.ERROR_BROKEN_PIPE { return 0, io.EOF } else { return n, err } }
[ "func", "(", "f", "*", "win32File", ")", "Read", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "c", ",", "err", ":=", "f", ".", "prepareIo", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "defer", "f", ".", "wg", ".", "Done", "(", ")", "\n\n", "if", "f", ".", "readDeadline", ".", "timedout", ".", "isSet", "(", ")", "{", "return", "0", ",", "ErrTimeout", "\n", "}", "\n\n", "var", "bytes", "uint32", "\n", "err", "=", "syscall", ".", "ReadFile", "(", "f", ".", "handle", ",", "b", ",", "&", "bytes", ",", "&", "c", ".", "o", ")", "\n", "n", ",", "err", ":=", "f", ".", "asyncIo", "(", "c", ",", "&", "f", ".", "readDeadline", ",", "bytes", ",", "err", ")", "\n", "runtime", ".", "KeepAlive", "(", "b", ")", "\n\n", "// Handle EOF conditions.", "if", "err", "==", "nil", "&&", "n", "==", "0", "&&", "len", "(", "b", ")", "!=", "0", "{", "return", "0", ",", "io", ".", "EOF", "\n", "}", "else", "if", "err", "==", "syscall", ".", "ERROR_BROKEN_PIPE", "{", "return", "0", ",", "io", ".", "EOF", "\n", "}", "else", "{", "return", "n", ",", "err", "\n", "}", "\n", "}" ]
// Read reads from a file handle.
[ "Read", "reads", "from", "a", "file", "handle", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/file.go#L217-L241
150,745
Microsoft/go-winio
file.go
Write
func (f *win32File) Write(b []byte) (int, error) { c, err := f.prepareIo() if err != nil { return 0, err } defer f.wg.Done() if f.writeDeadline.timedout.isSet() { return 0, ErrTimeout } var bytes uint32 err = syscall.WriteFile(f.handle, b, &bytes, &c.o) n, err := f.asyncIo(c, &f.writeDeadline, bytes, err) runtime.KeepAlive(b) return n, err }
go
func (f *win32File) Write(b []byte) (int, error) { c, err := f.prepareIo() if err != nil { return 0, err } defer f.wg.Done() if f.writeDeadline.timedout.isSet() { return 0, ErrTimeout } var bytes uint32 err = syscall.WriteFile(f.handle, b, &bytes, &c.o) n, err := f.asyncIo(c, &f.writeDeadline, bytes, err) runtime.KeepAlive(b) return n, err }
[ "func", "(", "f", "*", "win32File", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "c", ",", "err", ":=", "f", ".", "prepareIo", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "defer", "f", ".", "wg", ".", "Done", "(", ")", "\n\n", "if", "f", ".", "writeDeadline", ".", "timedout", ".", "isSet", "(", ")", "{", "return", "0", ",", "ErrTimeout", "\n", "}", "\n\n", "var", "bytes", "uint32", "\n", "err", "=", "syscall", ".", "WriteFile", "(", "f", ".", "handle", ",", "b", ",", "&", "bytes", ",", "&", "c", ".", "o", ")", "\n", "n", ",", "err", ":=", "f", ".", "asyncIo", "(", "c", ",", "&", "f", ".", "writeDeadline", ",", "bytes", ",", "err", ")", "\n", "runtime", ".", "KeepAlive", "(", "b", ")", "\n", "return", "n", ",", "err", "\n", "}" ]
// Write writes to a file handle.
[ "Write", "writes", "to", "a", "file", "handle", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/file.go#L244-L260
150,746
Microsoft/go-winio
pkg/etw/eventdata.go
writeString
func (ed *eventData) writeString(data string) { ed.buffer.WriteString(data) ed.buffer.WriteByte(0) }
go
func (ed *eventData) writeString(data string) { ed.buffer.WriteString(data) ed.buffer.WriteByte(0) }
[ "func", "(", "ed", "*", "eventData", ")", "writeString", "(", "data", "string", ")", "{", "ed", ".", "buffer", ".", "WriteString", "(", "data", ")", "\n", "ed", ".", "buffer", ".", "WriteByte", "(", "0", ")", "\n", "}" ]
// writeString appends a string, including the null terminator, to the buffer.
[ "writeString", "appends", "a", "string", "including", "the", "null", "terminator", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L22-L25
150,747
Microsoft/go-winio
pkg/etw/eventdata.go
writeInt8
func (ed *eventData) writeInt8(value int8) { ed.buffer.WriteByte(uint8(value)) }
go
func (ed *eventData) writeInt8(value int8) { ed.buffer.WriteByte(uint8(value)) }
[ "func", "(", "ed", "*", "eventData", ")", "writeInt8", "(", "value", "int8", ")", "{", "ed", ".", "buffer", ".", "WriteByte", "(", "uint8", "(", "value", ")", ")", "\n", "}" ]
// writeInt8 appends a int8 to the buffer.
[ "writeInt8", "appends", "a", "int8", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L28-L30
150,748
Microsoft/go-winio
pkg/etw/eventdata.go
writeInt16
func (ed *eventData) writeInt16(value int16) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
go
func (ed *eventData) writeInt16(value int16) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
[ "func", "(", "ed", "*", "eventData", ")", "writeInt16", "(", "value", "int16", ")", "{", "binary", ".", "Write", "(", "&", "ed", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "value", ")", "\n", "}" ]
// writeInt16 appends a int16 to the buffer.
[ "writeInt16", "appends", "a", "int16", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L33-L35
150,749
Microsoft/go-winio
pkg/etw/eventdata.go
writeInt32
func (ed *eventData) writeInt32(value int32) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
go
func (ed *eventData) writeInt32(value int32) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
[ "func", "(", "ed", "*", "eventData", ")", "writeInt32", "(", "value", "int32", ")", "{", "binary", ".", "Write", "(", "&", "ed", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "value", ")", "\n", "}" ]
// writeInt32 appends a int32 to the buffer.
[ "writeInt32", "appends", "a", "int32", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L38-L40
150,750
Microsoft/go-winio
pkg/etw/eventdata.go
writeInt64
func (ed *eventData) writeInt64(value int64) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
go
func (ed *eventData) writeInt64(value int64) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
[ "func", "(", "ed", "*", "eventData", ")", "writeInt64", "(", "value", "int64", ")", "{", "binary", ".", "Write", "(", "&", "ed", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "value", ")", "\n", "}" ]
// writeInt64 appends a int64 to the buffer.
[ "writeInt64", "appends", "a", "int64", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L43-L45
150,751
Microsoft/go-winio
pkg/etw/eventdata.go
writeUint16
func (ed *eventData) writeUint16(value uint16) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
go
func (ed *eventData) writeUint16(value uint16) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
[ "func", "(", "ed", "*", "eventData", ")", "writeUint16", "(", "value", "uint16", ")", "{", "binary", ".", "Write", "(", "&", "ed", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "value", ")", "\n", "}" ]
// writeUint16 appends a uint16 to the buffer.
[ "writeUint16", "appends", "a", "uint16", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L53-L55
150,752
Microsoft/go-winio
pkg/etw/eventdata.go
writeUint32
func (ed *eventData) writeUint32(value uint32) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
go
func (ed *eventData) writeUint32(value uint32) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
[ "func", "(", "ed", "*", "eventData", ")", "writeUint32", "(", "value", "uint32", ")", "{", "binary", ".", "Write", "(", "&", "ed", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "value", ")", "\n", "}" ]
// writeUint32 appends a uint32 to the buffer.
[ "writeUint32", "appends", "a", "uint32", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L58-L60
150,753
Microsoft/go-winio
pkg/etw/eventdata.go
writeUint64
func (ed *eventData) writeUint64(value uint64) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
go
func (ed *eventData) writeUint64(value uint64) { binary.Write(&ed.buffer, binary.LittleEndian, value) }
[ "func", "(", "ed", "*", "eventData", ")", "writeUint64", "(", "value", "uint64", ")", "{", "binary", ".", "Write", "(", "&", "ed", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "value", ")", "\n", "}" ]
// writeUint64 appends a uint64 to the buffer.
[ "writeUint64", "appends", "a", "uint64", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventdata.go#L63-L65
150,754
Microsoft/go-winio
pkg/etw/eventopt.go
WithLevel
func WithLevel(level Level) EventOpt { return func(options *eventOptions) { options.descriptor.level = level } }
go
func WithLevel(level Level) EventOpt { return func(options *eventOptions) { options.descriptor.level = level } }
[ "func", "WithLevel", "(", "level", "Level", ")", "EventOpt", "{", "return", "func", "(", "options", "*", "eventOptions", ")", "{", "options", ".", "descriptor", ".", "level", "=", "level", "\n", "}", "\n", "}" ]
// WithLevel specifies the level of the event to be written.
[ "WithLevel", "specifies", "the", "level", "of", "the", "event", "to", "be", "written", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventopt.go#L25-L29
150,755
Microsoft/go-winio
pkg/etw/eventopt.go
WithKeyword
func WithKeyword(keyword uint64) EventOpt { return func(options *eventOptions) { options.descriptor.keyword |= keyword } }
go
func WithKeyword(keyword uint64) EventOpt { return func(options *eventOptions) { options.descriptor.keyword |= keyword } }
[ "func", "WithKeyword", "(", "keyword", "uint64", ")", "EventOpt", "{", "return", "func", "(", "options", "*", "eventOptions", ")", "{", "options", ".", "descriptor", ".", "keyword", "|=", "keyword", "\n", "}", "\n", "}" ]
// WithKeyword specifies the keywords of the event to be written. Multiple uses // of this option are OR'd together.
[ "WithKeyword", "specifies", "the", "keywords", "of", "the", "event", "to", "be", "written", ".", "Multiple", "uses", "of", "this", "option", "are", "OR", "d", "together", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventopt.go#L33-L37
150,756
Microsoft/go-winio
pkg/etw/eventopt.go
WithChannel
func WithChannel(channel Channel) EventOpt { return func(options *eventOptions) { options.descriptor.channel = channel } }
go
func WithChannel(channel Channel) EventOpt { return func(options *eventOptions) { options.descriptor.channel = channel } }
[ "func", "WithChannel", "(", "channel", "Channel", ")", "EventOpt", "{", "return", "func", "(", "options", "*", "eventOptions", ")", "{", "options", ".", "descriptor", ".", "channel", "=", "channel", "\n", "}", "\n", "}" ]
// WithChannel specifies the channel of the event to be written.
[ "WithChannel", "specifies", "the", "channel", "of", "the", "event", "to", "be", "written", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventopt.go#L40-L44
150,757
Microsoft/go-winio
pkg/etw/eventopt.go
WithOpcode
func WithOpcode(opcode Opcode) EventOpt { return func(options *eventOptions) { options.descriptor.opcode = opcode } }
go
func WithOpcode(opcode Opcode) EventOpt { return func(options *eventOptions) { options.descriptor.opcode = opcode } }
[ "func", "WithOpcode", "(", "opcode", "Opcode", ")", "EventOpt", "{", "return", "func", "(", "options", "*", "eventOptions", ")", "{", "options", ".", "descriptor", ".", "opcode", "=", "opcode", "\n", "}", "\n", "}" ]
// WithOpcode specifies the opcode of the event to be written.
[ "WithOpcode", "specifies", "the", "opcode", "of", "the", "event", "to", "be", "written", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventopt.go#L47-L51
150,758
Microsoft/go-winio
pkg/etw/eventopt.go
WithActivityID
func WithActivityID(activityID *guid.GUID) EventOpt { return func(options *eventOptions) { options.activityID = activityID } }
go
func WithActivityID(activityID *guid.GUID) EventOpt { return func(options *eventOptions) { options.activityID = activityID } }
[ "func", "WithActivityID", "(", "activityID", "*", "guid", ".", "GUID", ")", "EventOpt", "{", "return", "func", "(", "options", "*", "eventOptions", ")", "{", "options", ".", "activityID", "=", "activityID", "\n", "}", "\n", "}" ]
// WithActivityID specifies the activity ID of the event to be written.
[ "WithActivityID", "specifies", "the", "activity", "ID", "of", "the", "event", "to", "be", "written", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventopt.go#L62-L66
150,759
Microsoft/go-winio
pkg/etw/eventopt.go
WithRelatedActivityID
func WithRelatedActivityID(activityID *guid.GUID) EventOpt { return func(options *eventOptions) { options.relatedActivityID = activityID } }
go
func WithRelatedActivityID(activityID *guid.GUID) EventOpt { return func(options *eventOptions) { options.relatedActivityID = activityID } }
[ "func", "WithRelatedActivityID", "(", "activityID", "*", "guid", ".", "GUID", ")", "EventOpt", "{", "return", "func", "(", "options", "*", "eventOptions", ")", "{", "options", ".", "relatedActivityID", "=", "activityID", "\n", "}", "\n", "}" ]
// WithRelatedActivityID specifies the parent activity ID of the event to be written.
[ "WithRelatedActivityID", "specifies", "the", "parent", "activity", "ID", "of", "the", "event", "to", "be", "written", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventopt.go#L69-L73
150,760
Microsoft/go-winio
pkg/etw/newprovider_unsupported.go
NewProviderWithID
func NewProviderWithID(name string, id *guid.GUID, callback EnableCallback) (provider *Provider, err error) { return nil, nil }
go
func NewProviderWithID(name string, id *guid.GUID, callback EnableCallback) (provider *Provider, err error) { return nil, nil }
[ "func", "NewProviderWithID", "(", "name", "string", ",", "id", "*", "guid", ".", "GUID", ",", "callback", "EnableCallback", ")", "(", "provider", "*", "Provider", ",", "err", "error", ")", "{", "return", "nil", ",", "nil", "\n", "}" ]
// NewProviderWithID returns a nil provider on unsupported platforms.
[ "NewProviderWithID", "returns", "a", "nil", "provider", "on", "unsupported", "platforms", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/newprovider_unsupported.go#L10-L12
150,761
Microsoft/go-winio
pkg/security/grantvmgroupaccess.go
generateDACLWithAcesAdded
func generateDACLWithAcesAdded(name string, isDir bool, origDACL uintptr) (uintptr, error) { // Generate pointers to the SIDs based on the string SIDs sid, err := syscall.StringToSid(sidVmGroup) if err != nil { return 0, errors.Wrapf(err, "%s syscall.StringToSid %s %s", gvmga, name, sidVmGroup) } inheritance := inheritModeNoInheritance if isDir { inheritance = inheritModeSubContainersAndObjectsInherit } eaArray := []explicitAccess{ explicitAccess{ accessPermissions: accessMaskDesiredPermission, accessMode: accessModeGrant, inheritance: inheritance, trustee: trustee{ trusteeForm: trusteeFormIsSid, trusteeType: trusteeTypeWellKnownGroup, name: uintptr(unsafe.Pointer(sid)), }, }, } modifiedDACL := uintptr(0) if err := setEntriesInAcl(uintptr(uint32(1)), uintptr(unsafe.Pointer(&eaArray[0])), origDACL, &modifiedDACL); err != nil { return 0, errors.Wrapf(err, "%s SetEntriesInAcl %s", gvmga, name) } return modifiedDACL, nil }
go
func generateDACLWithAcesAdded(name string, isDir bool, origDACL uintptr) (uintptr, error) { // Generate pointers to the SIDs based on the string SIDs sid, err := syscall.StringToSid(sidVmGroup) if err != nil { return 0, errors.Wrapf(err, "%s syscall.StringToSid %s %s", gvmga, name, sidVmGroup) } inheritance := inheritModeNoInheritance if isDir { inheritance = inheritModeSubContainersAndObjectsInherit } eaArray := []explicitAccess{ explicitAccess{ accessPermissions: accessMaskDesiredPermission, accessMode: accessModeGrant, inheritance: inheritance, trustee: trustee{ trusteeForm: trusteeFormIsSid, trusteeType: trusteeTypeWellKnownGroup, name: uintptr(unsafe.Pointer(sid)), }, }, } modifiedDACL := uintptr(0) if err := setEntriesInAcl(uintptr(uint32(1)), uintptr(unsafe.Pointer(&eaArray[0])), origDACL, &modifiedDACL); err != nil { return 0, errors.Wrapf(err, "%s SetEntriesInAcl %s", gvmga, name) } return modifiedDACL, nil }
[ "func", "generateDACLWithAcesAdded", "(", "name", "string", ",", "isDir", "bool", ",", "origDACL", "uintptr", ")", "(", "uintptr", ",", "error", ")", "{", "// Generate pointers to the SIDs based on the string SIDs", "sid", ",", "err", ":=", "syscall", ".", "StringToSid", "(", "sidVmGroup", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "gvmga", ",", "name", ",", "sidVmGroup", ")", "\n", "}", "\n\n", "inheritance", ":=", "inheritModeNoInheritance", "\n", "if", "isDir", "{", "inheritance", "=", "inheritModeSubContainersAndObjectsInherit", "\n", "}", "\n\n", "eaArray", ":=", "[", "]", "explicitAccess", "{", "explicitAccess", "{", "accessPermissions", ":", "accessMaskDesiredPermission", ",", "accessMode", ":", "accessModeGrant", ",", "inheritance", ":", "inheritance", ",", "trustee", ":", "trustee", "{", "trusteeForm", ":", "trusteeFormIsSid", ",", "trusteeType", ":", "trusteeTypeWellKnownGroup", ",", "name", ":", "uintptr", "(", "unsafe", ".", "Pointer", "(", "sid", ")", ")", ",", "}", ",", "}", ",", "}", "\n\n", "modifiedDACL", ":=", "uintptr", "(", "0", ")", "\n", "if", "err", ":=", "setEntriesInAcl", "(", "uintptr", "(", "uint32", "(", "1", ")", ")", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "&", "eaArray", "[", "0", "]", ")", ")", ",", "origDACL", ",", "&", "modifiedDACL", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "gvmga", ",", "name", ")", "\n", "}", "\n\n", "return", "modifiedDACL", ",", "nil", "\n", "}" ]
// generateDACLWithAcesAdded generates a new DACL with the two needed ACEs added. // The caller is responsible for LocalFree of the returned DACL on success.
[ "generateDACLWithAcesAdded", "generates", "a", "new", "DACL", "with", "the", "two", "needed", "ACEs", "added", ".", "The", "caller", "is", "responsible", "for", "LocalFree", "of", "the", "returned", "DACL", "on", "success", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/security/grantvmgroupaccess.go#L128-L159
150,762
Microsoft/go-winio
pkg/etw/newprovider.go
NewProviderWithID
func NewProviderWithID(name string, id *guid.GUID, callback EnableCallback) (provider *Provider, err error) { providerCallbackOnce.Do(func() { globalProviderCallback = windows.NewCallback(providerCallbackAdapter) }) provider = providers.newProvider() defer func(provider *Provider) { if err != nil { providers.removeProvider(provider) } }(provider) provider.ID = id provider.callback = callback if err := eventRegister((*windows.GUID)(provider.ID), globalProviderCallback, uintptr(provider.index), &provider.handle); err != nil { return nil, err } metadata := &bytes.Buffer{} binary.Write(metadata, binary.LittleEndian, uint16(0)) // Write empty size for buffer (to update later) metadata.WriteString(name) metadata.WriteByte(0) // Null terminator for name binary.LittleEndian.PutUint16(metadata.Bytes(), uint16(metadata.Len())) // Update the size at the beginning of the buffer provider.metadata = metadata.Bytes() if err := eventSetInformation( provider.handle, eventInfoClassProviderSetTraits, uintptr(unsafe.Pointer(&provider.metadata[0])), uint32(len(provider.metadata))); err != nil { return nil, err } return provider, nil }
go
func NewProviderWithID(name string, id *guid.GUID, callback EnableCallback) (provider *Provider, err error) { providerCallbackOnce.Do(func() { globalProviderCallback = windows.NewCallback(providerCallbackAdapter) }) provider = providers.newProvider() defer func(provider *Provider) { if err != nil { providers.removeProvider(provider) } }(provider) provider.ID = id provider.callback = callback if err := eventRegister((*windows.GUID)(provider.ID), globalProviderCallback, uintptr(provider.index), &provider.handle); err != nil { return nil, err } metadata := &bytes.Buffer{} binary.Write(metadata, binary.LittleEndian, uint16(0)) // Write empty size for buffer (to update later) metadata.WriteString(name) metadata.WriteByte(0) // Null terminator for name binary.LittleEndian.PutUint16(metadata.Bytes(), uint16(metadata.Len())) // Update the size at the beginning of the buffer provider.metadata = metadata.Bytes() if err := eventSetInformation( provider.handle, eventInfoClassProviderSetTraits, uintptr(unsafe.Pointer(&provider.metadata[0])), uint32(len(provider.metadata))); err != nil { return nil, err } return provider, nil }
[ "func", "NewProviderWithID", "(", "name", "string", ",", "id", "*", "guid", ".", "GUID", ",", "callback", "EnableCallback", ")", "(", "provider", "*", "Provider", ",", "err", "error", ")", "{", "providerCallbackOnce", ".", "Do", "(", "func", "(", ")", "{", "globalProviderCallback", "=", "windows", ".", "NewCallback", "(", "providerCallbackAdapter", ")", "\n", "}", ")", "\n\n", "provider", "=", "providers", ".", "newProvider", "(", ")", "\n", "defer", "func", "(", "provider", "*", "Provider", ")", "{", "if", "err", "!=", "nil", "{", "providers", ".", "removeProvider", "(", "provider", ")", "\n", "}", "\n", "}", "(", "provider", ")", "\n", "provider", ".", "ID", "=", "id", "\n", "provider", ".", "callback", "=", "callback", "\n\n", "if", "err", ":=", "eventRegister", "(", "(", "*", "windows", ".", "GUID", ")", "(", "provider", ".", "ID", ")", ",", "globalProviderCallback", ",", "uintptr", "(", "provider", ".", "index", ")", ",", "&", "provider", ".", "handle", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "metadata", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "binary", ".", "Write", "(", "metadata", ",", "binary", ".", "LittleEndian", ",", "uint16", "(", "0", ")", ")", "// Write empty size for buffer (to update later)", "\n", "metadata", ".", "WriteString", "(", "name", ")", "\n", "metadata", ".", "WriteByte", "(", "0", ")", "// Null terminator for name", "\n", "binary", ".", "LittleEndian", ".", "PutUint16", "(", "metadata", ".", "Bytes", "(", ")", ",", "uint16", "(", "metadata", ".", "Len", "(", ")", ")", ")", "// Update the size at the beginning of the buffer", "\n", "provider", ".", "metadata", "=", "metadata", ".", "Bytes", "(", ")", "\n\n", "if", "err", ":=", "eventSetInformation", "(", "provider", ".", "handle", ",", "eventInfoClassProviderSetTraits", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "&", "provider", ".", "metadata", "[", "0", "]", ")", ")", ",", "uint32", "(", "len", "(", "provider", ".", "metadata", ")", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "provider", ",", "nil", "\n", "}" ]
// NewProviderWithID creates and registers a new ETW provider, allowing the // provider ID to be manually specified. This is most useful when there is an // existing provider ID that must be used to conform to existing diagnostic // infrastructure.
[ "NewProviderWithID", "creates", "and", "registers", "a", "new", "ETW", "provider", "allowing", "the", "provider", "ID", "to", "be", "manually", "specified", ".", "This", "is", "most", "useful", "when", "there", "is", "an", "existing", "provider", "ID", "that", "must", "be", "used", "to", "conform", "to", "existing", "diagnostic", "infrastructure", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/newprovider.go#L18-L53
150,763
Microsoft/go-winio
pkg/etw/provider.go
NewProvider
func NewProvider(name string, callback EnableCallback) (provider *Provider, err error) { return NewProviderWithID(name, providerIDFromName(name), callback) }
go
func NewProvider(name string, callback EnableCallback) (provider *Provider, err error) { return NewProviderWithID(name, providerIDFromName(name), callback) }
[ "func", "NewProvider", "(", "name", "string", ",", "callback", "EnableCallback", ")", "(", "provider", "*", "Provider", ",", "err", "error", ")", "{", "return", "NewProviderWithID", "(", "name", ",", "providerIDFromName", "(", "name", ")", ",", "callback", ")", "\n", "}" ]
// NewProvider creates and registers a new ETW provider. The provider ID is // generated based on the provider name.
[ "NewProvider", "creates", "and", "registers", "a", "new", "ETW", "provider", ".", "The", "provider", "ID", "is", "generated", "based", "on", "the", "provider", "name", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/provider.go#L121-L123
150,764
Microsoft/go-winio
pkg/etw/provider.go
Close
func (provider *Provider) Close() error { if provider == nil { return nil } providers.removeProvider(provider) return eventUnregister(provider.handle) }
go
func (provider *Provider) Close() error { if provider == nil { return nil } providers.removeProvider(provider) return eventUnregister(provider.handle) }
[ "func", "(", "provider", "*", "Provider", ")", "Close", "(", ")", "error", "{", "if", "provider", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "providers", ".", "removeProvider", "(", "provider", ")", "\n", "return", "eventUnregister", "(", "provider", ".", "handle", ")", "\n", "}" ]
// Close unregisters the provider.
[ "Close", "unregisters", "the", "provider", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/provider.go#L126-L133
150,765
Microsoft/go-winio
pkg/etw/provider.go
IsEnabledForLevel
func (provider *Provider) IsEnabledForLevel(level Level) bool { return provider.IsEnabledForLevelAndKeywords(level, ^uint64(0)) }
go
func (provider *Provider) IsEnabledForLevel(level Level) bool { return provider.IsEnabledForLevelAndKeywords(level, ^uint64(0)) }
[ "func", "(", "provider", "*", "Provider", ")", "IsEnabledForLevel", "(", "level", "Level", ")", "bool", "{", "return", "provider", ".", "IsEnabledForLevelAndKeywords", "(", "level", ",", "^", "uint64", "(", "0", ")", ")", "\n", "}" ]
// IsEnabledForLevel calls IsEnabledForLevelAndKeywords with the specified level // and all keywords set.
[ "IsEnabledForLevel", "calls", "IsEnabledForLevelAndKeywords", "with", "the", "specified", "level", "and", "all", "keywords", "set", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/provider.go#L143-L145
150,766
Microsoft/go-winio
pkg/etw/provider.go
IsEnabledForLevelAndKeywords
func (provider *Provider) IsEnabledForLevelAndKeywords(level Level, keywords uint64) bool { if provider == nil { return false } if !provider.enabled { return false } // ETW automatically sets the level to 255 if it is specified as 0, so we // don't need to worry about the level=0 (all events) case. if level > provider.level { return false } if keywords != 0 && (keywords&provider.keywordAny == 0 || keywords&provider.keywordAll != provider.keywordAll) { return false } return true }
go
func (provider *Provider) IsEnabledForLevelAndKeywords(level Level, keywords uint64) bool { if provider == nil { return false } if !provider.enabled { return false } // ETW automatically sets the level to 255 if it is specified as 0, so we // don't need to worry about the level=0 (all events) case. if level > provider.level { return false } if keywords != 0 && (keywords&provider.keywordAny == 0 || keywords&provider.keywordAll != provider.keywordAll) { return false } return true }
[ "func", "(", "provider", "*", "Provider", ")", "IsEnabledForLevelAndKeywords", "(", "level", "Level", ",", "keywords", "uint64", ")", "bool", "{", "if", "provider", "==", "nil", "{", "return", "false", "\n", "}", "\n\n", "if", "!", "provider", ".", "enabled", "{", "return", "false", "\n", "}", "\n\n", "// ETW automatically sets the level to 255 if it is specified as 0, so we", "// don't need to worry about the level=0 (all events) case.", "if", "level", ">", "provider", ".", "level", "{", "return", "false", "\n", "}", "\n\n", "if", "keywords", "!=", "0", "&&", "(", "keywords", "&", "provider", ".", "keywordAny", "==", "0", "||", "keywords", "&", "provider", ".", "keywordAll", "!=", "provider", ".", "keywordAll", ")", "{", "return", "false", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
// IsEnabledForLevelAndKeywords allows event producer code to check if there are // any event sessions that are interested in an event, based on the event level // and keywords. Although this check happens automatically in the ETW // infrastructure, it can be useful to check if an event will actually be // consumed before doing expensive work to build the event data.
[ "IsEnabledForLevelAndKeywords", "allows", "event", "producer", "code", "to", "check", "if", "there", "are", "any", "event", "sessions", "that", "are", "interested", "in", "an", "event", "based", "on", "the", "event", "level", "and", "keywords", ".", "Although", "this", "check", "happens", "automatically", "in", "the", "ETW", "infrastructure", "it", "can", "be", "useful", "to", "check", "if", "an", "event", "will", "actually", "be", "consumed", "before", "doing", "expensive", "work", "to", "build", "the", "event", "data", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/provider.go#L152-L172
150,767
Microsoft/go-winio
pkg/etw/provider.go
WriteEvent
func (provider *Provider) WriteEvent(name string, eventOpts []EventOpt, fieldOpts []FieldOpt) error { if provider == nil { return nil } options := eventOptions{descriptor: newEventDescriptor()} em := &eventMetadata{} ed := &eventData{} // We need to evaluate the EventOpts first since they might change tags, and // we write out the tags before evaluating FieldOpts. for _, opt := range eventOpts { opt(&options) } if !provider.IsEnabledForLevelAndKeywords(options.descriptor.level, options.descriptor.keyword) { return nil } em.writeEventHeader(name, options.tags) for _, opt := range fieldOpts { opt(em, ed) } // Don't pass a data blob if there is no event data. There will always be // event metadata (e.g. for the name) so we don't need to do this check for // the metadata. dataBlobs := [][]byte{} if len(ed.bytes()) > 0 { dataBlobs = [][]byte{ed.bytes()} } return provider.writeEventRaw(options.descriptor, options.activityID, options.relatedActivityID, [][]byte{em.bytes()}, dataBlobs) }
go
func (provider *Provider) WriteEvent(name string, eventOpts []EventOpt, fieldOpts []FieldOpt) error { if provider == nil { return nil } options := eventOptions{descriptor: newEventDescriptor()} em := &eventMetadata{} ed := &eventData{} // We need to evaluate the EventOpts first since they might change tags, and // we write out the tags before evaluating FieldOpts. for _, opt := range eventOpts { opt(&options) } if !provider.IsEnabledForLevelAndKeywords(options.descriptor.level, options.descriptor.keyword) { return nil } em.writeEventHeader(name, options.tags) for _, opt := range fieldOpts { opt(em, ed) } // Don't pass a data blob if there is no event data. There will always be // event metadata (e.g. for the name) so we don't need to do this check for // the metadata. dataBlobs := [][]byte{} if len(ed.bytes()) > 0 { dataBlobs = [][]byte{ed.bytes()} } return provider.writeEventRaw(options.descriptor, options.activityID, options.relatedActivityID, [][]byte{em.bytes()}, dataBlobs) }
[ "func", "(", "provider", "*", "Provider", ")", "WriteEvent", "(", "name", "string", ",", "eventOpts", "[", "]", "EventOpt", ",", "fieldOpts", "[", "]", "FieldOpt", ")", "error", "{", "if", "provider", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "options", ":=", "eventOptions", "{", "descriptor", ":", "newEventDescriptor", "(", ")", "}", "\n", "em", ":=", "&", "eventMetadata", "{", "}", "\n", "ed", ":=", "&", "eventData", "{", "}", "\n\n", "// We need to evaluate the EventOpts first since they might change tags, and", "// we write out the tags before evaluating FieldOpts.", "for", "_", ",", "opt", ":=", "range", "eventOpts", "{", "opt", "(", "&", "options", ")", "\n", "}", "\n\n", "if", "!", "provider", ".", "IsEnabledForLevelAndKeywords", "(", "options", ".", "descriptor", ".", "level", ",", "options", ".", "descriptor", ".", "keyword", ")", "{", "return", "nil", "\n", "}", "\n\n", "em", ".", "writeEventHeader", "(", "name", ",", "options", ".", "tags", ")", "\n\n", "for", "_", ",", "opt", ":=", "range", "fieldOpts", "{", "opt", "(", "em", ",", "ed", ")", "\n", "}", "\n\n", "// Don't pass a data blob if there is no event data. There will always be", "// event metadata (e.g. for the name) so we don't need to do this check for", "// the metadata.", "dataBlobs", ":=", "[", "]", "[", "]", "byte", "{", "}", "\n", "if", "len", "(", "ed", ".", "bytes", "(", ")", ")", ">", "0", "{", "dataBlobs", "=", "[", "]", "[", "]", "byte", "{", "ed", ".", "bytes", "(", ")", "}", "\n", "}", "\n\n", "return", "provider", ".", "writeEventRaw", "(", "options", ".", "descriptor", ",", "options", ".", "activityID", ",", "options", ".", "relatedActivityID", ",", "[", "]", "[", "]", "byte", "{", "em", ".", "bytes", "(", ")", "}", ",", "dataBlobs", ")", "\n", "}" ]
// WriteEvent writes a single ETW event from the provider. The event is // constructed based on the EventOpt and FieldOpt values that are passed as // opts.
[ "WriteEvent", "writes", "a", "single", "ETW", "event", "from", "the", "provider", ".", "The", "event", "is", "constructed", "based", "on", "the", "EventOpt", "and", "FieldOpt", "values", "that", "are", "passed", "as", "opts", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/provider.go#L177-L211
150,768
Microsoft/go-winio
pkg/etw/provider.go
writeEventRaw
func (provider *Provider) writeEventRaw( descriptor *eventDescriptor, activityID *guid.GUID, relatedActivityID *guid.GUID, metadataBlobs [][]byte, dataBlobs [][]byte) error { dataDescriptorCount := uint32(1 + len(metadataBlobs) + len(dataBlobs)) dataDescriptors := make([]eventDataDescriptor, 0, dataDescriptorCount) dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeProviderMetadata, provider.metadata)) for _, blob := range metadataBlobs { dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeEventMetadata, blob)) } for _, blob := range dataBlobs { dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeUserData, blob)) } return eventWriteTransfer(provider.handle, descriptor, (*windows.GUID)(activityID), (*windows.GUID)(relatedActivityID), dataDescriptorCount, &dataDescriptors[0]) }
go
func (provider *Provider) writeEventRaw( descriptor *eventDescriptor, activityID *guid.GUID, relatedActivityID *guid.GUID, metadataBlobs [][]byte, dataBlobs [][]byte) error { dataDescriptorCount := uint32(1 + len(metadataBlobs) + len(dataBlobs)) dataDescriptors := make([]eventDataDescriptor, 0, dataDescriptorCount) dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeProviderMetadata, provider.metadata)) for _, blob := range metadataBlobs { dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeEventMetadata, blob)) } for _, blob := range dataBlobs { dataDescriptors = append(dataDescriptors, newEventDataDescriptor(eventDataDescriptorTypeUserData, blob)) } return eventWriteTransfer(provider.handle, descriptor, (*windows.GUID)(activityID), (*windows.GUID)(relatedActivityID), dataDescriptorCount, &dataDescriptors[0]) }
[ "func", "(", "provider", "*", "Provider", ")", "writeEventRaw", "(", "descriptor", "*", "eventDescriptor", ",", "activityID", "*", "guid", ".", "GUID", ",", "relatedActivityID", "*", "guid", ".", "GUID", ",", "metadataBlobs", "[", "]", "[", "]", "byte", ",", "dataBlobs", "[", "]", "[", "]", "byte", ")", "error", "{", "dataDescriptorCount", ":=", "uint32", "(", "1", "+", "len", "(", "metadataBlobs", ")", "+", "len", "(", "dataBlobs", ")", ")", "\n", "dataDescriptors", ":=", "make", "(", "[", "]", "eventDataDescriptor", ",", "0", ",", "dataDescriptorCount", ")", "\n\n", "dataDescriptors", "=", "append", "(", "dataDescriptors", ",", "newEventDataDescriptor", "(", "eventDataDescriptorTypeProviderMetadata", ",", "provider", ".", "metadata", ")", ")", "\n", "for", "_", ",", "blob", ":=", "range", "metadataBlobs", "{", "dataDescriptors", "=", "append", "(", "dataDescriptors", ",", "newEventDataDescriptor", "(", "eventDataDescriptorTypeEventMetadata", ",", "blob", ")", ")", "\n", "}", "\n", "for", "_", ",", "blob", ":=", "range", "dataBlobs", "{", "dataDescriptors", "=", "append", "(", "dataDescriptors", ",", "newEventDataDescriptor", "(", "eventDataDescriptorTypeUserData", ",", "blob", ")", ")", "\n", "}", "\n\n", "return", "eventWriteTransfer", "(", "provider", ".", "handle", ",", "descriptor", ",", "(", "*", "windows", ".", "GUID", ")", "(", "activityID", ")", ",", "(", "*", "windows", ".", "GUID", ")", "(", "relatedActivityID", ")", ",", "dataDescriptorCount", ",", "&", "dataDescriptors", "[", "0", "]", ")", "\n", "}" ]
// writeEventRaw writes a single ETW event from the provider. This function is // less abstracted than WriteEvent, and presents a fairly direct interface to // the event writing functionality. It expects a series of event metadata and // event data blobs to be passed in, which must conform to the TraceLogging // schema. The functions on EventMetadata and EventData can help with creating // these blobs. The blobs of each type are effectively concatenated together by // the ETW infrastructure.
[ "writeEventRaw", "writes", "a", "single", "ETW", "event", "from", "the", "provider", ".", "This", "function", "is", "less", "abstracted", "than", "WriteEvent", "and", "presents", "a", "fairly", "direct", "interface", "to", "the", "event", "writing", "functionality", ".", "It", "expects", "a", "series", "of", "event", "metadata", "and", "event", "data", "blobs", "to", "be", "passed", "in", "which", "must", "conform", "to", "the", "TraceLogging", "schema", ".", "The", "functions", "on", "EventMetadata", "and", "EventData", "can", "help", "with", "creating", "these", "blobs", ".", "The", "blobs", "of", "each", "type", "are", "effectively", "concatenated", "together", "by", "the", "ETW", "infrastructure", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/provider.go#L220-L239
150,769
Microsoft/go-winio
archive/tar/writer.go
formatString
func (f *formatter) formatString(b []byte, s string) { if len(s) > len(b) { f.err = ErrFieldTooLong return } ascii := toASCII(s) copy(b, ascii) if len(ascii) < len(b) { b[len(ascii)] = 0 } }
go
func (f *formatter) formatString(b []byte, s string) { if len(s) > len(b) { f.err = ErrFieldTooLong return } ascii := toASCII(s) copy(b, ascii) if len(ascii) < len(b) { b[len(ascii)] = 0 } }
[ "func", "(", "f", "*", "formatter", ")", "formatString", "(", "b", "[", "]", "byte", ",", "s", "string", ")", "{", "if", "len", "(", "s", ")", ">", "len", "(", "b", ")", "{", "f", ".", "err", "=", "ErrFieldTooLong", "\n", "return", "\n", "}", "\n", "ascii", ":=", "toASCII", "(", "s", ")", "\n", "copy", "(", "b", ",", "ascii", ")", "\n", "if", "len", "(", "ascii", ")", "<", "len", "(", "b", ")", "{", "b", "[", "len", "(", "ascii", ")", "]", "=", "0", "\n", "}", "\n", "}" ]
// Write s into b, terminating it with a NUL if there is room.
[ "Write", "s", "into", "b", "terminating", "it", "with", "a", "NUL", "if", "there", "is", "room", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/archive/tar/writer.go#L75-L85
150,770
Microsoft/go-winio
archive/tar/writer.go
formatOctal
func (f *formatter) formatOctal(b []byte, x int64) { s := strconv.FormatInt(x, 8) // leading zeros, but leave room for a NUL. for len(s)+1 < len(b) { s = "0" + s } f.formatString(b, s) }
go
func (f *formatter) formatOctal(b []byte, x int64) { s := strconv.FormatInt(x, 8) // leading zeros, but leave room for a NUL. for len(s)+1 < len(b) { s = "0" + s } f.formatString(b, s) }
[ "func", "(", "f", "*", "formatter", ")", "formatOctal", "(", "b", "[", "]", "byte", ",", "x", "int64", ")", "{", "s", ":=", "strconv", ".", "FormatInt", "(", "x", ",", "8", ")", "\n", "// leading zeros, but leave room for a NUL.", "for", "len", "(", "s", ")", "+", "1", "<", "len", "(", "b", ")", "{", "s", "=", "\"", "\"", "+", "s", "\n", "}", "\n", "f", ".", "formatString", "(", "b", ",", "s", ")", "\n", "}" ]
// Encode x as an octal ASCII string and write it into b with leading zeros.
[ "Encode", "x", "as", "an", "octal", "ASCII", "string", "and", "write", "it", "into", "b", "with", "leading", "zeros", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/archive/tar/writer.go#L88-L95
150,771
Microsoft/go-winio
archive/tar/writer.go
Write
func (tw *Writer) Write(b []byte) (n int, err error) { if tw.closed { err = ErrWriteAfterClose return } overwrite := false if int64(len(b)) > tw.nb { b = b[0:tw.nb] overwrite = true } n, err = tw.w.Write(b) tw.nb -= int64(n) if err == nil && overwrite { err = ErrWriteTooLong return } tw.err = err return }
go
func (tw *Writer) Write(b []byte) (n int, err error) { if tw.closed { err = ErrWriteAfterClose return } overwrite := false if int64(len(b)) > tw.nb { b = b[0:tw.nb] overwrite = true } n, err = tw.w.Write(b) tw.nb -= int64(n) if err == nil && overwrite { err = ErrWriteTooLong return } tw.err = err return }
[ "func", "(", "tw", "*", "Writer", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "if", "tw", ".", "closed", "{", "err", "=", "ErrWriteAfterClose", "\n", "return", "\n", "}", "\n", "overwrite", ":=", "false", "\n", "if", "int64", "(", "len", "(", "b", ")", ")", ">", "tw", ".", "nb", "{", "b", "=", "b", "[", "0", ":", "tw", ".", "nb", "]", "\n", "overwrite", "=", "true", "\n", "}", "\n", "n", ",", "err", "=", "tw", ".", "w", ".", "Write", "(", "b", ")", "\n", "tw", ".", "nb", "-=", "int64", "(", "n", ")", "\n", "if", "err", "==", "nil", "&&", "overwrite", "{", "err", "=", "ErrWriteTooLong", "\n", "return", "\n", "}", "\n", "tw", ".", "err", "=", "err", "\n", "return", "\n", "}" ]
// Write writes to the current entry in the tar archive. // Write returns the error ErrWriteTooLong if more than // hdr.Size bytes are written after WriteHeader.
[ "Write", "writes", "to", "the", "current", "entry", "in", "the", "tar", "archive", ".", "Write", "returns", "the", "error", "ErrWriteTooLong", "if", "more", "than", "hdr", ".", "Size", "bytes", "are", "written", "after", "WriteHeader", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/archive/tar/writer.go#L404-L422
150,772
Microsoft/go-winio
archive/tar/writer.go
Close
func (tw *Writer) Close() error { if tw.err != nil || tw.closed { return tw.err } tw.Flush() tw.closed = true if tw.err != nil { return tw.err } // trailer: two zero blocks for i := 0; i < 2; i++ { _, tw.err = tw.w.Write(zeroBlock) if tw.err != nil { break } } return tw.err }
go
func (tw *Writer) Close() error { if tw.err != nil || tw.closed { return tw.err } tw.Flush() tw.closed = true if tw.err != nil { return tw.err } // trailer: two zero blocks for i := 0; i < 2; i++ { _, tw.err = tw.w.Write(zeroBlock) if tw.err != nil { break } } return tw.err }
[ "func", "(", "tw", "*", "Writer", ")", "Close", "(", ")", "error", "{", "if", "tw", ".", "err", "!=", "nil", "||", "tw", ".", "closed", "{", "return", "tw", ".", "err", "\n", "}", "\n", "tw", ".", "Flush", "(", ")", "\n", "tw", ".", "closed", "=", "true", "\n", "if", "tw", ".", "err", "!=", "nil", "{", "return", "tw", ".", "err", "\n", "}", "\n\n", "// trailer: two zero blocks", "for", "i", ":=", "0", ";", "i", "<", "2", ";", "i", "++", "{", "_", ",", "tw", ".", "err", "=", "tw", ".", "w", ".", "Write", "(", "zeroBlock", ")", "\n", "if", "tw", ".", "err", "!=", "nil", "{", "break", "\n", "}", "\n", "}", "\n", "return", "tw", ".", "err", "\n", "}" ]
// Close closes the tar archive, flushing any unwritten // data to the underlying writer.
[ "Close", "closes", "the", "tar", "archive", "flushing", "any", "unwritten", "data", "to", "the", "underlying", "writer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/archive/tar/writer.go#L426-L444
150,773
Microsoft/go-winio
fileinfo.go
GetFileBasicInfo
func GetFileBasicInfo(f *os.File) (*FileBasicInfo, error) { bi := &FileBasicInfo{} if err := getFileInformationByHandleEx(syscall.Handle(f.Fd()), fileBasicInfo, (*byte)(unsafe.Pointer(bi)), uint32(unsafe.Sizeof(*bi))); err != nil { return nil, &os.PathError{Op: "GetFileInformationByHandleEx", Path: f.Name(), Err: err} } runtime.KeepAlive(f) return bi, nil }
go
func GetFileBasicInfo(f *os.File) (*FileBasicInfo, error) { bi := &FileBasicInfo{} if err := getFileInformationByHandleEx(syscall.Handle(f.Fd()), fileBasicInfo, (*byte)(unsafe.Pointer(bi)), uint32(unsafe.Sizeof(*bi))); err != nil { return nil, &os.PathError{Op: "GetFileInformationByHandleEx", Path: f.Name(), Err: err} } runtime.KeepAlive(f) return bi, nil }
[ "func", "GetFileBasicInfo", "(", "f", "*", "os", ".", "File", ")", "(", "*", "FileBasicInfo", ",", "error", ")", "{", "bi", ":=", "&", "FileBasicInfo", "{", "}", "\n", "if", "err", ":=", "getFileInformationByHandleEx", "(", "syscall", ".", "Handle", "(", "f", ".", "Fd", "(", ")", ")", ",", "fileBasicInfo", ",", "(", "*", "byte", ")", "(", "unsafe", ".", "Pointer", "(", "bi", ")", ")", ",", "uint32", "(", "unsafe", ".", "Sizeof", "(", "*", "bi", ")", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "&", "os", ".", "PathError", "{", "Op", ":", "\"", "\"", ",", "Path", ":", "f", ".", "Name", "(", ")", ",", "Err", ":", "err", "}", "\n", "}", "\n", "runtime", ".", "KeepAlive", "(", "f", ")", "\n", "return", "bi", ",", "nil", "\n", "}" ]
// GetFileBasicInfo retrieves times and attributes for a file.
[ "GetFileBasicInfo", "retrieves", "times", "and", "attributes", "for", "a", "file", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/fileinfo.go#L28-L35
150,774
Microsoft/go-winio
pkg/etw/eventmetadata.go
bytes
func (em *eventMetadata) bytes() []byte { // Finalize the event metadata buffer by filling in the buffer length at the // beginning. binary.LittleEndian.PutUint16(em.buffer.Bytes(), uint16(em.buffer.Len())) return em.buffer.Bytes() }
go
func (em *eventMetadata) bytes() []byte { // Finalize the event metadata buffer by filling in the buffer length at the // beginning. binary.LittleEndian.PutUint16(em.buffer.Bytes(), uint16(em.buffer.Len())) return em.buffer.Bytes() }
[ "func", "(", "em", "*", "eventMetadata", ")", "bytes", "(", ")", "[", "]", "byte", "{", "// Finalize the event metadata buffer by filling in the buffer length at the", "// beginning.", "binary", ".", "LittleEndian", ".", "PutUint16", "(", "em", ".", "buffer", ".", "Bytes", "(", ")", ",", "uint16", "(", "em", ".", "buffer", ".", "Len", "(", ")", ")", ")", "\n", "return", "em", ".", "buffer", ".", "Bytes", "(", ")", "\n", "}" ]
// bytes returns the raw binary data containing the event metadata. Before being // returned, the current size of the buffer is written to the start of the // buffer. The returned value is not copied from the internal buffer, so it can // be mutated by the eventMetadata object after it is returned.
[ "bytes", "returns", "the", "raw", "binary", "data", "containing", "the", "event", "metadata", ".", "Before", "being", "returned", "the", "current", "size", "of", "the", "buffer", "is", "written", "to", "the", "start", "of", "the", "buffer", ".", "The", "returned", "value", "is", "not", "copied", "from", "the", "internal", "buffer", "so", "it", "can", "be", "mutated", "by", "the", "eventMetadata", "object", "after", "it", "is", "returned", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventmetadata.go#L88-L93
150,775
Microsoft/go-winio
pkg/etw/eventmetadata.go
writeEventHeader
func (em *eventMetadata) writeEventHeader(name string, tags uint32) { binary.Write(&em.buffer, binary.LittleEndian, uint16(0)) // Length placeholder em.writeTags(tags) em.buffer.WriteString(name) em.buffer.WriteByte(0) // Null terminator for name }
go
func (em *eventMetadata) writeEventHeader(name string, tags uint32) { binary.Write(&em.buffer, binary.LittleEndian, uint16(0)) // Length placeholder em.writeTags(tags) em.buffer.WriteString(name) em.buffer.WriteByte(0) // Null terminator for name }
[ "func", "(", "em", "*", "eventMetadata", ")", "writeEventHeader", "(", "name", "string", ",", "tags", "uint32", ")", "{", "binary", ".", "Write", "(", "&", "em", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "uint16", "(", "0", ")", ")", "// Length placeholder", "\n", "em", ".", "writeTags", "(", "tags", ")", "\n", "em", ".", "buffer", ".", "WriteString", "(", "name", ")", "\n", "em", ".", "buffer", ".", "WriteByte", "(", "0", ")", "// Null terminator for name", "\n", "}" ]
// writeEventHeader writes the metadata for the start of an event to the buffer. // This specifies the event name and tags.
[ "writeEventHeader", "writes", "the", "metadata", "for", "the", "start", "of", "an", "event", "to", "the", "buffer", ".", "This", "specifies", "the", "event", "name", "and", "tags", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventmetadata.go#L97-L102
150,776
Microsoft/go-winio
pkg/etw/eventmetadata.go
writeField
func (em *eventMetadata) writeField(name string, inType inType, outType outType, tags uint32) { em.writeFieldInner(name, inType, outType, tags, 0) }
go
func (em *eventMetadata) writeField(name string, inType inType, outType outType, tags uint32) { em.writeFieldInner(name, inType, outType, tags, 0) }
[ "func", "(", "em", "*", "eventMetadata", ")", "writeField", "(", "name", "string", ",", "inType", "inType", ",", "outType", "outType", ",", "tags", "uint32", ")", "{", "em", ".", "writeFieldInner", "(", "name", ",", "inType", ",", "outType", ",", "tags", ",", "0", ")", "\n", "}" ]
// writeField writes the metadata for a simple field to the buffer.
[ "writeField", "writes", "the", "metadata", "for", "a", "simple", "field", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventmetadata.go#L154-L156
150,777
Microsoft/go-winio
pkg/etw/eventmetadata.go
writeArray
func (em *eventMetadata) writeArray(name string, inType inType, outType outType, tags uint32) { em.writeFieldInner(name, inType|inTypeArray, outType, tags, 0) }
go
func (em *eventMetadata) writeArray(name string, inType inType, outType outType, tags uint32) { em.writeFieldInner(name, inType|inTypeArray, outType, tags, 0) }
[ "func", "(", "em", "*", "eventMetadata", ")", "writeArray", "(", "name", "string", ",", "inType", "inType", ",", "outType", "outType", ",", "tags", "uint32", ")", "{", "em", ".", "writeFieldInner", "(", "name", ",", "inType", "|", "inTypeArray", ",", "outType", ",", "tags", ",", "0", ")", "\n", "}" ]
// writeArray writes the metadata for an array field to the buffer. The number // of elements in the array must be written as a uint16 in the event data, // immediately preceeding the event data.
[ "writeArray", "writes", "the", "metadata", "for", "an", "array", "field", "to", "the", "buffer", ".", "The", "number", "of", "elements", "in", "the", "array", "must", "be", "written", "as", "a", "uint16", "in", "the", "event", "data", "immediately", "preceeding", "the", "event", "data", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventmetadata.go#L161-L163
150,778
Microsoft/go-winio
pkg/etw/eventmetadata.go
writeCountedArray
func (em *eventMetadata) writeCountedArray(name string, count uint16, inType inType, outType outType, tags uint32) { em.writeFieldInner(name, inType|inTypeCountedArray, outType, tags, count) }
go
func (em *eventMetadata) writeCountedArray(name string, count uint16, inType inType, outType outType, tags uint32) { em.writeFieldInner(name, inType|inTypeCountedArray, outType, tags, count) }
[ "func", "(", "em", "*", "eventMetadata", ")", "writeCountedArray", "(", "name", "string", ",", "count", "uint16", ",", "inType", "inType", ",", "outType", "outType", ",", "tags", "uint32", ")", "{", "em", ".", "writeFieldInner", "(", "name", ",", "inType", "|", "inTypeCountedArray", ",", "outType", ",", "tags", ",", "count", ")", "\n", "}" ]
// writeCountedArray writes the metadata for an array field to the buffer. The // size of a counted array is fixed, and the size is written into the metadata // directly.
[ "writeCountedArray", "writes", "the", "metadata", "for", "an", "array", "field", "to", "the", "buffer", ".", "The", "size", "of", "a", "counted", "array", "is", "fixed", "and", "the", "size", "is", "written", "into", "the", "metadata", "directly", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventmetadata.go#L168-L170
150,779
Microsoft/go-winio
pkg/etw/eventmetadata.go
writeStruct
func (em *eventMetadata) writeStruct(name string, fieldCount uint8, tags uint32) { em.writeFieldInner(name, inTypeStruct, outType(fieldCount), tags, 0) }
go
func (em *eventMetadata) writeStruct(name string, fieldCount uint8, tags uint32) { em.writeFieldInner(name, inTypeStruct, outType(fieldCount), tags, 0) }
[ "func", "(", "em", "*", "eventMetadata", ")", "writeStruct", "(", "name", "string", ",", "fieldCount", "uint8", ",", "tags", "uint32", ")", "{", "em", ".", "writeFieldInner", "(", "name", ",", "inTypeStruct", ",", "outType", "(", "fieldCount", ")", ",", "tags", ",", "0", ")", "\n", "}" ]
// writeStruct writes the metadata for a nested struct to the buffer. The struct // contains the next N fields in the metadata, where N is specified by the // fieldCount argument.
[ "writeStruct", "writes", "the", "metadata", "for", "a", "nested", "struct", "to", "the", "buffer", ".", "The", "struct", "contains", "the", "next", "N", "fields", "in", "the", "metadata", "where", "N", "is", "specified", "by", "the", "fieldCount", "argument", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventmetadata.go#L175-L177
150,780
Microsoft/go-winio
pkg/security/mksyscall_windows.go
IsNotDuplicate
func (f *Fn) IsNotDuplicate() bool { funcName := f.DLLFuncName() if uniqDllFuncName[funcName] == false { uniqDllFuncName[funcName] = true return true } return false }
go
func (f *Fn) IsNotDuplicate() bool { funcName := f.DLLFuncName() if uniqDllFuncName[funcName] == false { uniqDllFuncName[funcName] = true return true } return false }
[ "func", "(", "f", "*", "Fn", ")", "IsNotDuplicate", "(", ")", "bool", "{", "funcName", ":=", "f", ".", "DLLFuncName", "(", ")", "\n", "if", "uniqDllFuncName", "[", "funcName", "]", "==", "false", "{", "uniqDllFuncName", "[", "funcName", "]", "=", "true", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsNotDuplicate is true if f is not a duplicated function
[ "IsNotDuplicate", "is", "true", "if", "f", "is", "not", "a", "duplicated", "function" ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/security/mksyscall_windows.go#L612-L619
150,781
Microsoft/go-winio
pkg/security/mksyscall_windows.go
Generate
func (src *Source) Generate(w io.Writer) error { const ( pkgStd = iota // any package in std library pkgXSysWindows // x/sys/windows package pkgOther ) isStdRepo, err := src.IsStdRepo() if err != nil { return err } var pkgtype int switch { case isStdRepo: pkgtype = pkgStd case packageName == "windows": // TODO: this needs better logic than just using package name pkgtype = pkgXSysWindows default: pkgtype = pkgOther } if *systemDLL { switch pkgtype { case pkgStd: src.Import("internal/syscall/windows/sysdll") case pkgXSysWindows: default: src.ExternalImport("golang.org/x/sys/windows") } } if *winio { src.ExternalImport("github.com/Microsoft/go-winio") } if packageName != "syscall" { src.Import("syscall") } funcMap := template.FuncMap{ "packagename": packagename, "syscalldot": syscalldot, "newlazydll": func(dll string) string { arg := "\"" + dll + ".dll\"" if !*systemDLL { return syscalldot() + "NewLazyDLL(" + arg + ")" } if strings.HasPrefix(dll, "api_") || strings.HasPrefix(dll, "ext_") { arg = strings.Replace(arg, "_", "-", -1) } switch pkgtype { case pkgStd: return syscalldot() + "NewLazyDLL(sysdll.Add(" + arg + "))" case pkgXSysWindows: return "NewLazySystemDLL(" + arg + ")" default: return "windows.NewLazySystemDLL(" + arg + ")" } }, } t := template.Must(template.New("main").Funcs(funcMap).Parse(srcTemplate)) err = t.Execute(w, src) if err != nil { return errors.New("Failed to execute template: " + err.Error()) } return nil }
go
func (src *Source) Generate(w io.Writer) error { const ( pkgStd = iota // any package in std library pkgXSysWindows // x/sys/windows package pkgOther ) isStdRepo, err := src.IsStdRepo() if err != nil { return err } var pkgtype int switch { case isStdRepo: pkgtype = pkgStd case packageName == "windows": // TODO: this needs better logic than just using package name pkgtype = pkgXSysWindows default: pkgtype = pkgOther } if *systemDLL { switch pkgtype { case pkgStd: src.Import("internal/syscall/windows/sysdll") case pkgXSysWindows: default: src.ExternalImport("golang.org/x/sys/windows") } } if *winio { src.ExternalImport("github.com/Microsoft/go-winio") } if packageName != "syscall" { src.Import("syscall") } funcMap := template.FuncMap{ "packagename": packagename, "syscalldot": syscalldot, "newlazydll": func(dll string) string { arg := "\"" + dll + ".dll\"" if !*systemDLL { return syscalldot() + "NewLazyDLL(" + arg + ")" } if strings.HasPrefix(dll, "api_") || strings.HasPrefix(dll, "ext_") { arg = strings.Replace(arg, "_", "-", -1) } switch pkgtype { case pkgStd: return syscalldot() + "NewLazyDLL(sysdll.Add(" + arg + "))" case pkgXSysWindows: return "NewLazySystemDLL(" + arg + ")" default: return "windows.NewLazySystemDLL(" + arg + ")" } }, } t := template.Must(template.New("main").Funcs(funcMap).Parse(srcTemplate)) err = t.Execute(w, src) if err != nil { return errors.New("Failed to execute template: " + err.Error()) } return nil }
[ "func", "(", "src", "*", "Source", ")", "Generate", "(", "w", "io", ".", "Writer", ")", "error", "{", "const", "(", "pkgStd", "=", "iota", "// any package in std library", "\n", "pkgXSysWindows", "// x/sys/windows package", "\n", "pkgOther", "\n", ")", "\n", "isStdRepo", ",", "err", ":=", "src", ".", "IsStdRepo", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "var", "pkgtype", "int", "\n", "switch", "{", "case", "isStdRepo", ":", "pkgtype", "=", "pkgStd", "\n", "case", "packageName", "==", "\"", "\"", ":", "// TODO: this needs better logic than just using package name", "pkgtype", "=", "pkgXSysWindows", "\n", "default", ":", "pkgtype", "=", "pkgOther", "\n", "}", "\n", "if", "*", "systemDLL", "{", "switch", "pkgtype", "{", "case", "pkgStd", ":", "src", ".", "Import", "(", "\"", "\"", ")", "\n", "case", "pkgXSysWindows", ":", "default", ":", "src", ".", "ExternalImport", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "if", "*", "winio", "{", "src", ".", "ExternalImport", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "packageName", "!=", "\"", "\"", "{", "src", ".", "Import", "(", "\"", "\"", ")", "\n", "}", "\n", "funcMap", ":=", "template", ".", "FuncMap", "{", "\"", "\"", ":", "packagename", ",", "\"", "\"", ":", "syscalldot", ",", "\"", "\"", ":", "func", "(", "dll", "string", ")", "string", "{", "arg", ":=", "\"", "\\\"", "\"", "+", "dll", "+", "\"", "\\\"", "\"", "\n", "if", "!", "*", "systemDLL", "{", "return", "syscalldot", "(", ")", "+", "\"", "\"", "+", "arg", "+", "\"", "\"", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "dll", ",", "\"", "\"", ")", "||", "strings", ".", "HasPrefix", "(", "dll", ",", "\"", "\"", ")", "{", "arg", "=", "strings", ".", "Replace", "(", "arg", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "}", "\n", "switch", "pkgtype", "{", "case", "pkgStd", ":", "return", "syscalldot", "(", ")", "+", "\"", "\"", "+", "arg", "+", "\"", "\"", "\n", "case", "pkgXSysWindows", ":", "return", "\"", "\"", "+", "arg", "+", "\"", "\"", "\n", "default", ":", "return", "\"", "\"", "+", "arg", "+", "\"", "\"", "\n", "}", "\n", "}", ",", "}", "\n", "t", ":=", "template", ".", "Must", "(", "template", ".", "New", "(", "\"", "\"", ")", ".", "Funcs", "(", "funcMap", ")", ".", "Parse", "(", "srcTemplate", ")", ")", "\n", "err", "=", "t", ".", "Execute", "(", "w", ",", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Generate output source file from a source set src.
[ "Generate", "output", "source", "file", "from", "a", "source", "set", "src", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/security/mksyscall_windows.go#L750-L812
150,782
godbus/dbus
decoder.go
newDecoder
func newDecoder(in io.Reader, order binary.ByteOrder) *decoder { dec := new(decoder) dec.in = in dec.order = order return dec }
go
func newDecoder(in io.Reader, order binary.ByteOrder) *decoder { dec := new(decoder) dec.in = in dec.order = order return dec }
[ "func", "newDecoder", "(", "in", "io", ".", "Reader", ",", "order", "binary", ".", "ByteOrder", ")", "*", "decoder", "{", "dec", ":=", "new", "(", "decoder", ")", "\n", "dec", ".", "in", "=", "in", "\n", "dec", ".", "order", "=", "order", "\n", "return", "dec", "\n", "}" ]
// newDecoder returns a new decoder that reads values from in. The input is // expected to be in the given byte order.
[ "newDecoder", "returns", "a", "new", "decoder", "that", "reads", "values", "from", "in", ".", "The", "input", "is", "expected", "to", "be", "in", "the", "given", "byte", "order", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/decoder.go#L17-L22
150,783
godbus/dbus
decoder.go
align
func (dec *decoder) align(n int) { if dec.pos%n != 0 { newpos := (dec.pos + n - 1) & ^(n - 1) empty := make([]byte, newpos-dec.pos) if _, err := io.ReadFull(dec.in, empty); err != nil { panic(err) } dec.pos = newpos } }
go
func (dec *decoder) align(n int) { if dec.pos%n != 0 { newpos := (dec.pos + n - 1) & ^(n - 1) empty := make([]byte, newpos-dec.pos) if _, err := io.ReadFull(dec.in, empty); err != nil { panic(err) } dec.pos = newpos } }
[ "func", "(", "dec", "*", "decoder", ")", "align", "(", "n", "int", ")", "{", "if", "dec", ".", "pos", "%", "n", "!=", "0", "{", "newpos", ":=", "(", "dec", ".", "pos", "+", "n", "-", "1", ")", "&", "^", "(", "n", "-", "1", ")", "\n", "empty", ":=", "make", "(", "[", "]", "byte", ",", "newpos", "-", "dec", ".", "pos", ")", "\n", "if", "_", ",", "err", ":=", "io", ".", "ReadFull", "(", "dec", ".", "in", ",", "empty", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "dec", ".", "pos", "=", "newpos", "\n", "}", "\n", "}" ]
// align aligns the input to the given boundary and panics on error.
[ "align", "aligns", "the", "input", "to", "the", "given", "boundary", "and", "panics", "on", "error", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/decoder.go#L25-L34
150,784
godbus/dbus
decoder.go
sigByteSize
func sigByteSize(sig string) int { var total int for offset := 0; offset < len(sig); { switch sig[offset] { case 'y': total += 1 offset += 1 case 'n', 'q': total += 2 offset += 1 case 'b', 'i', 'u', 'h': total += 4 offset += 1 case 'x', 't', 'd': total += 8 offset += 1 case '(': i := 1 depth := 1 for i < len(sig[offset:]) && depth != 0 { if sig[offset+i] == '(' { depth++ } else if sig[offset+i] == ')' { depth-- } i++ } s := sigByteSize(sig[offset+1 : offset+i-1]) if s == 0 { return 0 } total += s offset += i default: return 0 } } return total }
go
func sigByteSize(sig string) int { var total int for offset := 0; offset < len(sig); { switch sig[offset] { case 'y': total += 1 offset += 1 case 'n', 'q': total += 2 offset += 1 case 'b', 'i', 'u', 'h': total += 4 offset += 1 case 'x', 't', 'd': total += 8 offset += 1 case '(': i := 1 depth := 1 for i < len(sig[offset:]) && depth != 0 { if sig[offset+i] == '(' { depth++ } else if sig[offset+i] == ')' { depth-- } i++ } s := sigByteSize(sig[offset+1 : offset+i-1]) if s == 0 { return 0 } total += s offset += i default: return 0 } } return total }
[ "func", "sigByteSize", "(", "sig", "string", ")", "int", "{", "var", "total", "int", "\n", "for", "offset", ":=", "0", ";", "offset", "<", "len", "(", "sig", ")", ";", "{", "switch", "sig", "[", "offset", "]", "{", "case", "'y'", ":", "total", "+=", "1", "\n", "offset", "+=", "1", "\n", "case", "'n'", ",", "'q'", ":", "total", "+=", "2", "\n", "offset", "+=", "1", "\n", "case", "'b'", ",", "'i'", ",", "'u'", ",", "'h'", ":", "total", "+=", "4", "\n", "offset", "+=", "1", "\n", "case", "'x'", ",", "'t'", ",", "'d'", ":", "total", "+=", "8", "\n", "offset", "+=", "1", "\n", "case", "'('", ":", "i", ":=", "1", "\n", "depth", ":=", "1", "\n", "for", "i", "<", "len", "(", "sig", "[", "offset", ":", "]", ")", "&&", "depth", "!=", "0", "{", "if", "sig", "[", "offset", "+", "i", "]", "==", "'('", "{", "depth", "++", "\n", "}", "else", "if", "sig", "[", "offset", "+", "i", "]", "==", "')'", "{", "depth", "--", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "s", ":=", "sigByteSize", "(", "sig", "[", "offset", "+", "1", ":", "offset", "+", "i", "-", "1", "]", ")", "\n", "if", "s", "==", "0", "{", "return", "0", "\n", "}", "\n", "total", "+=", "s", "\n", "offset", "+=", "i", "\n", "default", ":", "return", "0", "\n", "}", "\n", "}", "\n", "return", "total", "\n", "}" ]
// sigByteSize tries to calculates size of the given signature in bytes. // // It returns zero when it can't, for example when it contains non-fixed size // types such as strings, maps and arrays that require reading of the transmitted // data, for that we would need to implement the unread method for Decoder first.
[ "sigByteSize", "tries", "to", "calculates", "size", "of", "the", "given", "signature", "in", "bytes", ".", "It", "returns", "zero", "when", "it", "can", "t", "for", "example", "when", "it", "contains", "non", "-", "fixed", "size", "types", "such", "as", "strings", "maps", "and", "arrays", "that", "require", "reading", "of", "the", "transmitted", "data", "for", "that", "we", "would", "need", "to", "implement", "the", "unread", "method", "for", "Decoder", "first", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/decoder.go#L241-L279
150,785
godbus/dbus
auth.go
authReadLine
func authReadLine(in *bufio.Reader) ([][]byte, error) { data, err := in.ReadBytes('\n') if err != nil { return nil, err } data = bytes.TrimSuffix(data, []byte("\r\n")) return bytes.Split(data, []byte{' '}), nil }
go
func authReadLine(in *bufio.Reader) ([][]byte, error) { data, err := in.ReadBytes('\n') if err != nil { return nil, err } data = bytes.TrimSuffix(data, []byte("\r\n")) return bytes.Split(data, []byte{' '}), nil }
[ "func", "authReadLine", "(", "in", "*", "bufio", ".", "Reader", ")", "(", "[", "]", "[", "]", "byte", ",", "error", ")", "{", "data", ",", "err", ":=", "in", ".", "ReadBytes", "(", "'\\n'", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "data", "=", "bytes", ".", "TrimSuffix", "(", "data", ",", "[", "]", "byte", "(", "\"", "\\r", "\\n", "\"", ")", ")", "\n", "return", "bytes", ".", "Split", "(", "data", ",", "[", "]", "byte", "{", "' '", "}", ")", ",", "nil", "\n", "}" ]
// authReadLine reads a line and separates it into its fields.
[ "authReadLine", "reads", "a", "line", "and", "separates", "it", "into", "its", "fields", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/auth.go#L223-L230
150,786
godbus/dbus
sig.go
SignatureOf
func SignatureOf(vs ...interface{}) Signature { var s string for _, v := range vs { s += getSignature(reflect.TypeOf(v)) } return Signature{s} }
go
func SignatureOf(vs ...interface{}) Signature { var s string for _, v := range vs { s += getSignature(reflect.TypeOf(v)) } return Signature{s} }
[ "func", "SignatureOf", "(", "vs", "...", "interface", "{", "}", ")", "Signature", "{", "var", "s", "string", "\n", "for", "_", ",", "v", ":=", "range", "vs", "{", "s", "+=", "getSignature", "(", "reflect", ".", "TypeOf", "(", "v", ")", ")", "\n", "}", "\n", "return", "Signature", "{", "s", "}", "\n", "}" ]
// SignatureOf returns the concatenation of all the signatures of the given // values. It panics if one of them is not representable in D-Bus.
[ "SignatureOf", "returns", "the", "concatenation", "of", "all", "the", "signatures", "of", "the", "given", "values", ".", "It", "panics", "if", "one", "of", "them", "is", "not", "representable", "in", "D", "-", "Bus", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L34-L40
150,787
godbus/dbus
sig.go
getSignature
func getSignature(t reflect.Type) string { // handle simple types first switch t.Kind() { case reflect.Uint8: return "y" case reflect.Bool: return "b" case reflect.Int16: return "n" case reflect.Uint16: return "q" case reflect.Int, reflect.Int32: if t == unixFDType { return "h" } return "i" case reflect.Uint, reflect.Uint32: if t == unixFDIndexType { return "h" } return "u" case reflect.Int64: return "x" case reflect.Uint64: return "t" case reflect.Float64: return "d" case reflect.Ptr: return getSignature(t.Elem()) case reflect.String: if t == objectPathType { return "o" } return "s" case reflect.Struct: if t == variantType { return "v" } else if t == signatureType { return "g" } var s string for i := 0; i < t.NumField(); i++ { field := t.Field(i) if field.PkgPath == "" && field.Tag.Get("dbus") != "-" { s += getSignature(t.Field(i).Type) } } return "(" + s + ")" case reflect.Array, reflect.Slice: return "a" + getSignature(t.Elem()) case reflect.Map: if !isKeyType(t.Key()) { panic(InvalidTypeError{t}) } return "a{" + getSignature(t.Key()) + getSignature(t.Elem()) + "}" case reflect.Interface: return "v" } panic(InvalidTypeError{t}) }
go
func getSignature(t reflect.Type) string { // handle simple types first switch t.Kind() { case reflect.Uint8: return "y" case reflect.Bool: return "b" case reflect.Int16: return "n" case reflect.Uint16: return "q" case reflect.Int, reflect.Int32: if t == unixFDType { return "h" } return "i" case reflect.Uint, reflect.Uint32: if t == unixFDIndexType { return "h" } return "u" case reflect.Int64: return "x" case reflect.Uint64: return "t" case reflect.Float64: return "d" case reflect.Ptr: return getSignature(t.Elem()) case reflect.String: if t == objectPathType { return "o" } return "s" case reflect.Struct: if t == variantType { return "v" } else if t == signatureType { return "g" } var s string for i := 0; i < t.NumField(); i++ { field := t.Field(i) if field.PkgPath == "" && field.Tag.Get("dbus") != "-" { s += getSignature(t.Field(i).Type) } } return "(" + s + ")" case reflect.Array, reflect.Slice: return "a" + getSignature(t.Elem()) case reflect.Map: if !isKeyType(t.Key()) { panic(InvalidTypeError{t}) } return "a{" + getSignature(t.Key()) + getSignature(t.Elem()) + "}" case reflect.Interface: return "v" } panic(InvalidTypeError{t}) }
[ "func", "getSignature", "(", "t", "reflect", ".", "Type", ")", "string", "{", "// handle simple types first", "switch", "t", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Uint8", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Bool", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Int16", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Uint16", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Int", ",", "reflect", ".", "Int32", ":", "if", "t", "==", "unixFDType", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "case", "reflect", ".", "Uint", ",", "reflect", ".", "Uint32", ":", "if", "t", "==", "unixFDIndexType", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "case", "reflect", ".", "Int64", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Uint64", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Float64", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Ptr", ":", "return", "getSignature", "(", "t", ".", "Elem", "(", ")", ")", "\n", "case", "reflect", ".", "String", ":", "if", "t", "==", "objectPathType", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "case", "reflect", ".", "Struct", ":", "if", "t", "==", "variantType", "{", "return", "\"", "\"", "\n", "}", "else", "if", "t", "==", "signatureType", "{", "return", "\"", "\"", "\n", "}", "\n", "var", "s", "string", "\n", "for", "i", ":=", "0", ";", "i", "<", "t", ".", "NumField", "(", ")", ";", "i", "++", "{", "field", ":=", "t", ".", "Field", "(", "i", ")", "\n", "if", "field", ".", "PkgPath", "==", "\"", "\"", "&&", "field", ".", "Tag", ".", "Get", "(", "\"", "\"", ")", "!=", "\"", "\"", "{", "s", "+=", "getSignature", "(", "t", ".", "Field", "(", "i", ")", ".", "Type", ")", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", "+", "s", "+", "\"", "\"", "\n", "case", "reflect", ".", "Array", ",", "reflect", ".", "Slice", ":", "return", "\"", "\"", "+", "getSignature", "(", "t", ".", "Elem", "(", ")", ")", "\n", "case", "reflect", ".", "Map", ":", "if", "!", "isKeyType", "(", "t", ".", "Key", "(", ")", ")", "{", "panic", "(", "InvalidTypeError", "{", "t", "}", ")", "\n", "}", "\n", "return", "\"", "\"", "+", "getSignature", "(", "t", ".", "Key", "(", ")", ")", "+", "getSignature", "(", "t", ".", "Elem", "(", ")", ")", "+", "\"", "\"", "\n", "case", "reflect", ".", "Interface", ":", "return", "\"", "\"", "\n", "}", "\n", "panic", "(", "InvalidTypeError", "{", "t", "}", ")", "\n", "}" ]
// getSignature returns the signature of the given type and panics on unknown types.
[ "getSignature", "returns", "the", "signature", "of", "the", "given", "type", "and", "panics", "on", "unknown", "types", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L49-L108
150,788
godbus/dbus
sig.go
ParseSignature
func ParseSignature(s string) (sig Signature, err error) { if len(s) == 0 { return } if len(s) > 255 { return Signature{""}, SignatureError{s, "too long"} } sig.str = s for err == nil && len(s) != 0 { err, s = validSingle(s, 0) } if err != nil { sig = Signature{""} } return }
go
func ParseSignature(s string) (sig Signature, err error) { if len(s) == 0 { return } if len(s) > 255 { return Signature{""}, SignatureError{s, "too long"} } sig.str = s for err == nil && len(s) != 0 { err, s = validSingle(s, 0) } if err != nil { sig = Signature{""} } return }
[ "func", "ParseSignature", "(", "s", "string", ")", "(", "sig", "Signature", ",", "err", "error", ")", "{", "if", "len", "(", "s", ")", "==", "0", "{", "return", "\n", "}", "\n", "if", "len", "(", "s", ")", ">", "255", "{", "return", "Signature", "{", "\"", "\"", "}", ",", "SignatureError", "{", "s", ",", "\"", "\"", "}", "\n", "}", "\n", "sig", ".", "str", "=", "s", "\n", "for", "err", "==", "nil", "&&", "len", "(", "s", ")", "!=", "0", "{", "err", ",", "s", "=", "validSingle", "(", "s", ",", "0", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "sig", "=", "Signature", "{", "\"", "\"", "}", "\n", "}", "\n\n", "return", "\n", "}" ]
// ParseSignature returns the signature represented by this string, or a // SignatureError if the string is not a valid signature.
[ "ParseSignature", "returns", "the", "signature", "represented", "by", "this", "string", "or", "a", "SignatureError", "if", "the", "string", "is", "not", "a", "valid", "signature", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L112-L128
150,789
godbus/dbus
sig.go
ParseSignatureMust
func ParseSignatureMust(s string) Signature { sig, err := ParseSignature(s) if err != nil { panic(err) } return sig }
go
func ParseSignatureMust(s string) Signature { sig, err := ParseSignature(s) if err != nil { panic(err) } return sig }
[ "func", "ParseSignatureMust", "(", "s", "string", ")", "Signature", "{", "sig", ",", "err", ":=", "ParseSignature", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "sig", "\n", "}" ]
// ParseSignatureMust behaves like ParseSignature, except that it panics if s // is not valid.
[ "ParseSignatureMust", "behaves", "like", "ParseSignature", "except", "that", "it", "panics", "if", "s", "is", "not", "valid", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L132-L138
150,790
godbus/dbus
sig.go
Single
func (s Signature) Single() bool { err, r := validSingle(s.str, 0) return err != nil && r == "" }
go
func (s Signature) Single() bool { err, r := validSingle(s.str, 0) return err != nil && r == "" }
[ "func", "(", "s", "Signature", ")", "Single", "(", ")", "bool", "{", "err", ",", "r", ":=", "validSingle", "(", "s", ".", "str", ",", "0", ")", "\n", "return", "err", "!=", "nil", "&&", "r", "==", "\"", "\"", "\n", "}" ]
// Single returns whether the signature represents a single, complete type.
[ "Single", "returns", "whether", "the", "signature", "represents", "a", "single", "complete", "type", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L146-L149
150,791
godbus/dbus
sig.go
validSingle
func validSingle(s string, depth int) (err error, rem string) { if s == "" { return SignatureError{Sig: s, Reason: "empty signature"}, "" } if depth > 64 { return SignatureError{Sig: s, Reason: "container nesting too deep"}, "" } switch s[0] { case 'y', 'b', 'n', 'q', 'i', 'u', 'x', 't', 'd', 's', 'g', 'o', 'v', 'h': return nil, s[1:] case 'a': if len(s) > 1 && s[1] == '{' { i := findMatching(s[1:], '{', '}') if i == -1 { return SignatureError{Sig: s, Reason: "unmatched '{'"}, "" } i++ rem = s[i+1:] s = s[2:i] if err, _ = validSingle(s[:1], depth+1); err != nil { return err, "" } err, nr := validSingle(s[1:], depth+1) if err != nil { return err, "" } if nr != "" { return SignatureError{Sig: s, Reason: "too many types in dict"}, "" } return nil, rem } return validSingle(s[1:], depth+1) case '(': i := findMatching(s, '(', ')') if i == -1 { return SignatureError{Sig: s, Reason: "unmatched ')'"}, "" } rem = s[i+1:] s = s[1:i] for err == nil && s != "" { err, s = validSingle(s, depth+1) } if err != nil { rem = "" } return } return SignatureError{Sig: s, Reason: "invalid type character"}, "" }
go
func validSingle(s string, depth int) (err error, rem string) { if s == "" { return SignatureError{Sig: s, Reason: "empty signature"}, "" } if depth > 64 { return SignatureError{Sig: s, Reason: "container nesting too deep"}, "" } switch s[0] { case 'y', 'b', 'n', 'q', 'i', 'u', 'x', 't', 'd', 's', 'g', 'o', 'v', 'h': return nil, s[1:] case 'a': if len(s) > 1 && s[1] == '{' { i := findMatching(s[1:], '{', '}') if i == -1 { return SignatureError{Sig: s, Reason: "unmatched '{'"}, "" } i++ rem = s[i+1:] s = s[2:i] if err, _ = validSingle(s[:1], depth+1); err != nil { return err, "" } err, nr := validSingle(s[1:], depth+1) if err != nil { return err, "" } if nr != "" { return SignatureError{Sig: s, Reason: "too many types in dict"}, "" } return nil, rem } return validSingle(s[1:], depth+1) case '(': i := findMatching(s, '(', ')') if i == -1 { return SignatureError{Sig: s, Reason: "unmatched ')'"}, "" } rem = s[i+1:] s = s[1:i] for err == nil && s != "" { err, s = validSingle(s, depth+1) } if err != nil { rem = "" } return } return SignatureError{Sig: s, Reason: "invalid type character"}, "" }
[ "func", "validSingle", "(", "s", "string", ",", "depth", "int", ")", "(", "err", "error", ",", "rem", "string", ")", "{", "if", "s", "==", "\"", "\"", "{", "return", "SignatureError", "{", "Sig", ":", "s", ",", "Reason", ":", "\"", "\"", "}", ",", "\"", "\"", "\n", "}", "\n", "if", "depth", ">", "64", "{", "return", "SignatureError", "{", "Sig", ":", "s", ",", "Reason", ":", "\"", "\"", "}", ",", "\"", "\"", "\n", "}", "\n", "switch", "s", "[", "0", "]", "{", "case", "'y'", ",", "'b'", ",", "'n'", ",", "'q'", ",", "'i'", ",", "'u'", ",", "'x'", ",", "'t'", ",", "'d'", ",", "'s'", ",", "'g'", ",", "'o'", ",", "'v'", ",", "'h'", ":", "return", "nil", ",", "s", "[", "1", ":", "]", "\n", "case", "'a'", ":", "if", "len", "(", "s", ")", ">", "1", "&&", "s", "[", "1", "]", "==", "'{'", "{", "i", ":=", "findMatching", "(", "s", "[", "1", ":", "]", ",", "'{'", ",", "'}'", ")", "\n", "if", "i", "==", "-", "1", "{", "return", "SignatureError", "{", "Sig", ":", "s", ",", "Reason", ":", "\"", "\"", "}", ",", "\"", "\"", "\n", "}", "\n", "i", "++", "\n", "rem", "=", "s", "[", "i", "+", "1", ":", "]", "\n", "s", "=", "s", "[", "2", ":", "i", "]", "\n", "if", "err", ",", "_", "=", "validSingle", "(", "s", "[", ":", "1", "]", ",", "depth", "+", "1", ")", ";", "err", "!=", "nil", "{", "return", "err", ",", "\"", "\"", "\n", "}", "\n", "err", ",", "nr", ":=", "validSingle", "(", "s", "[", "1", ":", "]", ",", "depth", "+", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", ",", "\"", "\"", "\n", "}", "\n", "if", "nr", "!=", "\"", "\"", "{", "return", "SignatureError", "{", "Sig", ":", "s", ",", "Reason", ":", "\"", "\"", "}", ",", "\"", "\"", "\n", "}", "\n", "return", "nil", ",", "rem", "\n", "}", "\n", "return", "validSingle", "(", "s", "[", "1", ":", "]", ",", "depth", "+", "1", ")", "\n", "case", "'('", ":", "i", ":=", "findMatching", "(", "s", ",", "'('", ",", "')'", ")", "\n", "if", "i", "==", "-", "1", "{", "return", "SignatureError", "{", "Sig", ":", "s", ",", "Reason", ":", "\"", "\"", "}", ",", "\"", "\"", "\n", "}", "\n", "rem", "=", "s", "[", "i", "+", "1", ":", "]", "\n", "s", "=", "s", "[", "1", ":", "i", "]", "\n", "for", "err", "==", "nil", "&&", "s", "!=", "\"", "\"", "{", "err", ",", "s", "=", "validSingle", "(", "s", ",", "depth", "+", "1", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "rem", "=", "\"", "\"", "\n", "}", "\n", "return", "\n", "}", "\n", "return", "SignatureError", "{", "Sig", ":", "s", ",", "Reason", ":", "\"", "\"", "}", ",", "\"", "\"", "\n", "}" ]
// Try to read a single type from this string. If it was successful, err is nil // and rem is the remaining unparsed part. Otherwise, err is a non-nil // SignatureError and rem is "". depth is the current recursion depth which may // not be greater than 64 and should be given as 0 on the first call.
[ "Try", "to", "read", "a", "single", "type", "from", "this", "string", ".", "If", "it", "was", "successful", "err", "is", "nil", "and", "rem", "is", "the", "remaining", "unparsed", "part", ".", "Otherwise", "err", "is", "a", "non", "-", "nil", "SignatureError", "and", "rem", "is", ".", "depth", "is", "the", "current", "recursion", "depth", "which", "may", "not", "be", "greater", "than", "64", "and", "should", "be", "given", "as", "0", "on", "the", "first", "call", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L171-L219
150,792
godbus/dbus
sig.go
typeFor
func typeFor(s string) (t reflect.Type) { err, _ := validSingle(s, 0) if err != nil { panic(err) } if t, ok := sigToType[s[0]]; ok { return t } switch s[0] { case 'a': if s[1] == '{' { i := strings.LastIndex(s, "}") t = reflect.MapOf(sigToType[s[2]], typeFor(s[3:i])) } else { t = reflect.SliceOf(typeFor(s[1:])) } case '(': t = interfacesType } return }
go
func typeFor(s string) (t reflect.Type) { err, _ := validSingle(s, 0) if err != nil { panic(err) } if t, ok := sigToType[s[0]]; ok { return t } switch s[0] { case 'a': if s[1] == '{' { i := strings.LastIndex(s, "}") t = reflect.MapOf(sigToType[s[2]], typeFor(s[3:i])) } else { t = reflect.SliceOf(typeFor(s[1:])) } case '(': t = interfacesType } return }
[ "func", "typeFor", "(", "s", "string", ")", "(", "t", "reflect", ".", "Type", ")", "{", "err", ",", "_", ":=", "validSingle", "(", "s", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n\n", "if", "t", ",", "ok", ":=", "sigToType", "[", "s", "[", "0", "]", "]", ";", "ok", "{", "return", "t", "\n", "}", "\n", "switch", "s", "[", "0", "]", "{", "case", "'a'", ":", "if", "s", "[", "1", "]", "==", "'{'", "{", "i", ":=", "strings", ".", "LastIndex", "(", "s", ",", "\"", "\"", ")", "\n", "t", "=", "reflect", ".", "MapOf", "(", "sigToType", "[", "s", "[", "2", "]", "]", ",", "typeFor", "(", "s", "[", "3", ":", "i", "]", ")", ")", "\n", "}", "else", "{", "t", "=", "reflect", ".", "SliceOf", "(", "typeFor", "(", "s", "[", "1", ":", "]", ")", ")", "\n", "}", "\n", "case", "'('", ":", "t", "=", "interfacesType", "\n", "}", "\n", "return", "\n", "}" ]
// typeFor returns the type of the given signature. It ignores any left over // characters and panics if s doesn't start with a valid type signature.
[ "typeFor", "returns", "the", "type", "of", "the", "given", "signature", ".", "It", "ignores", "any", "left", "over", "characters", "and", "panics", "if", "s", "doesn", "t", "start", "with", "a", "valid", "type", "signature", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L238-L259
150,793
godbus/dbus
prop/prop.go
Export
func Export( conn *dbus.Conn, path dbus.ObjectPath, props map[string]map[string]*Prop, ) (*Properties, error) { p := &Properties{m: props, conn: conn, path: path} if err := conn.Export(p, path, "org.freedesktop.DBus.Properties"); err != nil { return nil, err } return p, nil }
go
func Export( conn *dbus.Conn, path dbus.ObjectPath, props map[string]map[string]*Prop, ) (*Properties, error) { p := &Properties{m: props, conn: conn, path: path} if err := conn.Export(p, path, "org.freedesktop.DBus.Properties"); err != nil { return nil, err } return p, nil }
[ "func", "Export", "(", "conn", "*", "dbus", ".", "Conn", ",", "path", "dbus", ".", "ObjectPath", ",", "props", "map", "[", "string", "]", "map", "[", "string", "]", "*", "Prop", ",", ")", "(", "*", "Properties", ",", "error", ")", "{", "p", ":=", "&", "Properties", "{", "m", ":", "props", ",", "conn", ":", "conn", ",", "path", ":", "path", "}", "\n", "if", "err", ":=", "conn", ".", "Export", "(", "p", ",", "path", ",", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "p", ",", "nil", "\n", "}" ]
// Export returns a new Properties structure that manages the given properties. // The key for the first-level map of props is the name of the interface; the // second-level key is the name of the property. The returned structure will be // exported as org.freedesktop.DBus.Properties on path.
[ "Export", "returns", "a", "new", "Properties", "structure", "that", "manages", "the", "given", "properties", ".", "The", "key", "for", "the", "first", "-", "level", "map", "of", "props", "is", "the", "name", "of", "the", "interface", ";", "the", "second", "-", "level", "key", "is", "the", "name", "of", "the", "property", ".", "The", "returned", "structure", "will", "be", "exported", "as", "org", ".", "freedesktop", ".", "DBus", ".", "Properties", "on", "path", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L160-L168
150,794
godbus/dbus
prop/prop.go
Get
func (p *Properties) Get(iface, property string) (dbus.Variant, *dbus.Error) { p.mut.RLock() defer p.mut.RUnlock() m, ok := p.m[iface] if !ok { return dbus.Variant{}, ErrIfaceNotFound } prop, ok := m[property] if !ok { return dbus.Variant{}, ErrPropNotFound } return dbus.MakeVariant(prop.Value), nil }
go
func (p *Properties) Get(iface, property string) (dbus.Variant, *dbus.Error) { p.mut.RLock() defer p.mut.RUnlock() m, ok := p.m[iface] if !ok { return dbus.Variant{}, ErrIfaceNotFound } prop, ok := m[property] if !ok { return dbus.Variant{}, ErrPropNotFound } return dbus.MakeVariant(prop.Value), nil }
[ "func", "(", "p", "*", "Properties", ")", "Get", "(", "iface", ",", "property", "string", ")", "(", "dbus", ".", "Variant", ",", "*", "dbus", ".", "Error", ")", "{", "p", ".", "mut", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "mut", ".", "RUnlock", "(", ")", "\n", "m", ",", "ok", ":=", "p", ".", "m", "[", "iface", "]", "\n", "if", "!", "ok", "{", "return", "dbus", ".", "Variant", "{", "}", ",", "ErrIfaceNotFound", "\n", "}", "\n", "prop", ",", "ok", ":=", "m", "[", "property", "]", "\n", "if", "!", "ok", "{", "return", "dbus", ".", "Variant", "{", "}", ",", "ErrPropNotFound", "\n", "}", "\n", "return", "dbus", ".", "MakeVariant", "(", "prop", ".", "Value", ")", ",", "nil", "\n", "}" ]
// Get implements org.freedesktop.DBus.Properties.Get.
[ "Get", "implements", "org", ".", "freedesktop", ".", "DBus", ".", "Properties", ".", "Get", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L171-L183
150,795
godbus/dbus
prop/prop.go
GetAll
func (p *Properties) GetAll(iface string) (map[string]dbus.Variant, *dbus.Error) { p.mut.RLock() defer p.mut.RUnlock() m, ok := p.m[iface] if !ok { return nil, ErrIfaceNotFound } rm := make(map[string]dbus.Variant, len(m)) for k, v := range m { rm[k] = dbus.MakeVariant(v.Value) } return rm, nil }
go
func (p *Properties) GetAll(iface string) (map[string]dbus.Variant, *dbus.Error) { p.mut.RLock() defer p.mut.RUnlock() m, ok := p.m[iface] if !ok { return nil, ErrIfaceNotFound } rm := make(map[string]dbus.Variant, len(m)) for k, v := range m { rm[k] = dbus.MakeVariant(v.Value) } return rm, nil }
[ "func", "(", "p", "*", "Properties", ")", "GetAll", "(", "iface", "string", ")", "(", "map", "[", "string", "]", "dbus", ".", "Variant", ",", "*", "dbus", ".", "Error", ")", "{", "p", ".", "mut", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "mut", ".", "RUnlock", "(", ")", "\n", "m", ",", "ok", ":=", "p", ".", "m", "[", "iface", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "ErrIfaceNotFound", "\n", "}", "\n", "rm", ":=", "make", "(", "map", "[", "string", "]", "dbus", ".", "Variant", ",", "len", "(", "m", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "m", "{", "rm", "[", "k", "]", "=", "dbus", ".", "MakeVariant", "(", "v", ".", "Value", ")", "\n", "}", "\n", "return", "rm", ",", "nil", "\n", "}" ]
// GetAll implements org.freedesktop.DBus.Properties.GetAll.
[ "GetAll", "implements", "org", ".", "freedesktop", ".", "DBus", ".", "Properties", ".", "GetAll", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L186-L198
150,796
godbus/dbus
prop/prop.go
GetMust
func (p *Properties) GetMust(iface, property string) interface{} { p.mut.RLock() defer p.mut.RUnlock() return p.m[iface][property].Value }
go
func (p *Properties) GetMust(iface, property string) interface{} { p.mut.RLock() defer p.mut.RUnlock() return p.m[iface][property].Value }
[ "func", "(", "p", "*", "Properties", ")", "GetMust", "(", "iface", ",", "property", "string", ")", "interface", "{", "}", "{", "p", ".", "mut", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "mut", ".", "RUnlock", "(", ")", "\n", "return", "p", ".", "m", "[", "iface", "]", "[", "property", "]", ".", "Value", "\n", "}" ]
// GetMust returns the value of the given property and panics if either the // interface or the property name are invalid.
[ "GetMust", "returns", "the", "value", "of", "the", "given", "property", "and", "panics", "if", "either", "the", "interface", "or", "the", "property", "name", "are", "invalid", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L202-L206
150,797
godbus/dbus
prop/prop.go
Introspection
func (p *Properties) Introspection(iface string) []introspect.Property { p.mut.RLock() defer p.mut.RUnlock() m := p.m[iface] s := make([]introspect.Property, 0, len(m)) for k, v := range m { p := introspect.Property{Name: k, Type: dbus.SignatureOf(v.Value).String()} if v.Writable { p.Access = "readwrite" } else { p.Access = "read" } s = append(s, p) } return s }
go
func (p *Properties) Introspection(iface string) []introspect.Property { p.mut.RLock() defer p.mut.RUnlock() m := p.m[iface] s := make([]introspect.Property, 0, len(m)) for k, v := range m { p := introspect.Property{Name: k, Type: dbus.SignatureOf(v.Value).String()} if v.Writable { p.Access = "readwrite" } else { p.Access = "read" } s = append(s, p) } return s }
[ "func", "(", "p", "*", "Properties", ")", "Introspection", "(", "iface", "string", ")", "[", "]", "introspect", ".", "Property", "{", "p", ".", "mut", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "mut", ".", "RUnlock", "(", ")", "\n", "m", ":=", "p", ".", "m", "[", "iface", "]", "\n", "s", ":=", "make", "(", "[", "]", "introspect", ".", "Property", ",", "0", ",", "len", "(", "m", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "m", "{", "p", ":=", "introspect", ".", "Property", "{", "Name", ":", "k", ",", "Type", ":", "dbus", ".", "SignatureOf", "(", "v", ".", "Value", ")", ".", "String", "(", ")", "}", "\n", "if", "v", ".", "Writable", "{", "p", ".", "Access", "=", "\"", "\"", "\n", "}", "else", "{", "p", ".", "Access", "=", "\"", "\"", "\n", "}", "\n", "s", "=", "append", "(", "s", ",", "p", ")", "\n", "}", "\n", "return", "s", "\n", "}" ]
// Introspection returns the introspection data that represents the properties // of iface.
[ "Introspection", "returns", "the", "introspection", "data", "that", "represents", "the", "properties", "of", "iface", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L210-L225
150,798
godbus/dbus
prop/prop.go
set
func (p *Properties) set(iface, property string, v interface{}) error { prop := p.m[iface][property] prop.Value = v switch prop.Emit { case EmitFalse: return nil // do nothing case EmitInvalidates: return p.conn.Emit(p.path, "org.freedesktop.DBus.Properties.PropertiesChanged", iface, map[string]dbus.Variant{}, []string{property}) case EmitTrue: return p.conn.Emit(p.path, "org.freedesktop.DBus.Properties.PropertiesChanged", iface, map[string]dbus.Variant{property: dbus.MakeVariant(v)}, []string{}) default: panic("invalid value for EmitType") } }
go
func (p *Properties) set(iface, property string, v interface{}) error { prop := p.m[iface][property] prop.Value = v switch prop.Emit { case EmitFalse: return nil // do nothing case EmitInvalidates: return p.conn.Emit(p.path, "org.freedesktop.DBus.Properties.PropertiesChanged", iface, map[string]dbus.Variant{}, []string{property}) case EmitTrue: return p.conn.Emit(p.path, "org.freedesktop.DBus.Properties.PropertiesChanged", iface, map[string]dbus.Variant{property: dbus.MakeVariant(v)}, []string{}) default: panic("invalid value for EmitType") } }
[ "func", "(", "p", "*", "Properties", ")", "set", "(", "iface", ",", "property", "string", ",", "v", "interface", "{", "}", ")", "error", "{", "prop", ":=", "p", ".", "m", "[", "iface", "]", "[", "property", "]", "\n", "prop", ".", "Value", "=", "v", "\n", "switch", "prop", ".", "Emit", "{", "case", "EmitFalse", ":", "return", "nil", "// do nothing", "\n", "case", "EmitInvalidates", ":", "return", "p", ".", "conn", ".", "Emit", "(", "p", ".", "path", ",", "\"", "\"", ",", "iface", ",", "map", "[", "string", "]", "dbus", ".", "Variant", "{", "}", ",", "[", "]", "string", "{", "property", "}", ")", "\n", "case", "EmitTrue", ":", "return", "p", ".", "conn", ".", "Emit", "(", "p", ".", "path", ",", "\"", "\"", ",", "iface", ",", "map", "[", "string", "]", "dbus", ".", "Variant", "{", "property", ":", "dbus", ".", "MakeVariant", "(", "v", ")", "}", ",", "[", "]", "string", "{", "}", ")", "\n", "default", ":", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// set sets the given property and emits PropertyChanged if appropiate. p.mut // must already be locked.
[ "set", "sets", "the", "given", "property", "and", "emits", "PropertyChanged", "if", "appropiate", ".", "p", ".", "mut", "must", "already", "be", "locked", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L229-L245
150,799
godbus/dbus
prop/prop.go
Set
func (p *Properties) Set(iface, property string, newv dbus.Variant) *dbus.Error { p.mut.Lock() defer p.mut.Unlock() m, ok := p.m[iface] if !ok { return ErrIfaceNotFound } prop, ok := m[property] if !ok { return ErrPropNotFound } if !prop.Writable { return ErrReadOnly } if newv.Signature() != dbus.SignatureOf(prop.Value) { return ErrInvalidArg } if prop.Callback != nil { err := prop.Callback(&Change{p, iface, property, newv.Value()}) if err != nil { return err } } if err := p.set(iface, property, newv.Value()); err != nil { return dbus.MakeFailedError(err) } return nil }
go
func (p *Properties) Set(iface, property string, newv dbus.Variant) *dbus.Error { p.mut.Lock() defer p.mut.Unlock() m, ok := p.m[iface] if !ok { return ErrIfaceNotFound } prop, ok := m[property] if !ok { return ErrPropNotFound } if !prop.Writable { return ErrReadOnly } if newv.Signature() != dbus.SignatureOf(prop.Value) { return ErrInvalidArg } if prop.Callback != nil { err := prop.Callback(&Change{p, iface, property, newv.Value()}) if err != nil { return err } } if err := p.set(iface, property, newv.Value()); err != nil { return dbus.MakeFailedError(err) } return nil }
[ "func", "(", "p", "*", "Properties", ")", "Set", "(", "iface", ",", "property", "string", ",", "newv", "dbus", ".", "Variant", ")", "*", "dbus", ".", "Error", "{", "p", ".", "mut", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "mut", ".", "Unlock", "(", ")", "\n", "m", ",", "ok", ":=", "p", ".", "m", "[", "iface", "]", "\n", "if", "!", "ok", "{", "return", "ErrIfaceNotFound", "\n", "}", "\n", "prop", ",", "ok", ":=", "m", "[", "property", "]", "\n", "if", "!", "ok", "{", "return", "ErrPropNotFound", "\n", "}", "\n", "if", "!", "prop", ".", "Writable", "{", "return", "ErrReadOnly", "\n", "}", "\n", "if", "newv", ".", "Signature", "(", ")", "!=", "dbus", ".", "SignatureOf", "(", "prop", ".", "Value", ")", "{", "return", "ErrInvalidArg", "\n", "}", "\n", "if", "prop", ".", "Callback", "!=", "nil", "{", "err", ":=", "prop", ".", "Callback", "(", "&", "Change", "{", "p", ",", "iface", ",", "property", ",", "newv", ".", "Value", "(", ")", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "p", ".", "set", "(", "iface", ",", "property", ",", "newv", ".", "Value", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "dbus", ".", "MakeFailedError", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Set implements org.freedesktop.Properties.Set.
[ "Set", "implements", "org", ".", "freedesktop", ".", "Properties", ".", "Set", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L248-L275