How to use Read method of util Package

Best Gauge code snippet using util.Read

op.go

Source:op.go Github

copy

Full Screen

...11// See ./opcodes.go for a full list.12type Opcode byte13//go:generate go run ../../../_scripts/gen-opcodes.go opcodes.table opcodes.go14type stackfn func(Opcode, *context) error15type ReadMemoryFunc func([]byte, uint64) (int, error)16type context struct {17 buf *bytes.Buffer18 prog []byte19 stack []int6420 pieces []Piece21 ptrSize int22 DwarfRegisters23 readMemory ReadMemoryFunc24}25// Piece is a piece of memory stored either at an address or in a register.26type Piece struct {27 Size int28 Kind PieceKind29 Val uint6430 Bytes []byte31}32// PieceKind describes the kind of a piece.33type PieceKind uint834const (35 AddrPiece PieceKind = iota // The piece is stored in memory, Val is the address36 RegPiece // The piece is stored in a register, Val is the register number37 ImmPiece // The piece is an immediate value, Val or Bytes is the value38)39var (40 ErrStackUnderflow = errors.New("DWARF stack underflow")41 ErrStackIndexOutOfBounds = errors.New("DWARF stack index out of bounds")42 ErrMemoryReadUnavailable = errors.New("memory read unavailable")43)44const arbitraryExecutionLimitFactor = 1045// ExecuteStackProgram executes a DWARF location expression and returns46// either an address (int64), or a slice of Pieces for location expressions47// that don't evaluate to an address (such as register and composite expressions).48func ExecuteStackProgram(regs DwarfRegisters, instructions []byte, ptrSize int, readMemory ReadMemoryFunc) (int64, []Piece, error) {49 ctxt := &context{50 buf: bytes.NewBuffer(instructions),51 prog: instructions,52 stack: make([]int64, 0, 3),53 DwarfRegisters: regs,54 ptrSize: ptrSize,55 }56 for tick := 0; tick < len(instructions)*arbitraryExecutionLimitFactor; tick++ {57 opcodeByte, err := ctxt.buf.ReadByte()58 if err != nil {59 break60 }61 opcode := Opcode(opcodeByte)62 if opcode == DW_OP_nop {63 continue64 }65 fn, ok := oplut[opcode]66 if !ok {67 return 0, nil, fmt.Errorf("invalid instruction %#v", opcode)68 }69 err = fn(opcode, ctxt)70 if err != nil {71 return 0, nil, err72 }73 }74 if ctxt.pieces != nil {75 if len(ctxt.pieces) == 1 && ctxt.pieces[0].Kind == RegPiece {76 return int64(regs.Uint64Val(ctxt.pieces[0].Val)), ctxt.pieces, nil77 }78 return 0, ctxt.pieces, nil79 }80 if len(ctxt.stack) == 0 {81 return 0, nil, errors.New("empty OP stack")82 }83 return ctxt.stack[len(ctxt.stack)-1], nil, nil84}85// PrettyPrint prints the DWARF stack program instructions to `out`.86func PrettyPrint(out io.Writer, instructions []byte) {87 in := bytes.NewBuffer(instructions)88 for {89 opcode, err := in.ReadByte()90 if err != nil {91 break92 }93 if name, hasname := opcodeName[Opcode(opcode)]; hasname {94 io.WriteString(out, name)95 out.Write([]byte{' '})96 } else {97 fmt.Fprintf(out, "%#x ", opcode)98 }99 for _, arg := range opcodeArgs[Opcode(opcode)] {100 switch arg {101 case 's':102 n, _ := util.DecodeSLEB128(in)103 fmt.Fprintf(out, "%#x ", n)104 case 'u':105 n, _ := util.DecodeULEB128(in)106 fmt.Fprintf(out, "%#x ", n)107 case '1':108 var x uint8109 binary.Read(in, binary.LittleEndian, &x)110 fmt.Fprintf(out, "%#x ", x)111 case '2':112 var x uint16113 binary.Read(in, binary.LittleEndian, &x)114 fmt.Fprintf(out, "%#x ", x)115 case '4':116 var x uint32117 binary.Read(in, binary.LittleEndian, &x)118 fmt.Fprintf(out, "%#x ", x)119 case '8':120 var x uint64121 binary.Read(in, binary.LittleEndian, &x)122 fmt.Fprintf(out, "%#x ", x)123 case 'B':124 sz, _ := util.DecodeULEB128(in)125 data := make([]byte, sz)126 sz2, _ := in.Read(data)127 data = data[:sz2]128 fmt.Fprintf(out, "%d [%x] ", sz, data)129 }130 }131 }132}133// closeLoc is called by opcodes that can only appear at the end of a134// location expression (DW_OP_regN, DW_OP_regx, DW_OP_stack_value...).135// It checks that we are at the end of the program or that the following136// opcode is DW_OP_piece or DW_OP_bit_piece and processes them.137func (ctxt *context) closeLoc(opcode0 Opcode, piece Piece) error {138 if ctxt.buf.Len() == 0 {139 ctxt.pieces = append(ctxt.pieces, piece)140 return nil141 }142 // DWARF doesn't say what happens to the operand stack at the end of a143 // location expression, resetting it here.144 ctxt.stack = ctxt.stack[:0]145 b, err := ctxt.buf.ReadByte()146 if err != nil {147 return err148 }149 opcode := Opcode(b)150 switch opcode {151 case DW_OP_piece:152 sz, _ := util.DecodeULEB128(ctxt.buf)153 piece.Size = int(sz)154 ctxt.pieces = append(ctxt.pieces, piece)155 return nil156 case DW_OP_bit_piece:157 // not supported158 return fmt.Errorf("invalid instruction %#v", opcode)159 default:160 return fmt.Errorf("invalid instruction %#v after %#v", opcode, opcode0)161 }162}163func callframecfa(opcode Opcode, ctxt *context) error {164 if ctxt.CFA == 0 {165 return errors.New("could not retrieve CFA for current PC")166 }167 ctxt.stack = append(ctxt.stack, int64(ctxt.CFA))168 return nil169}170func addr(opcode Opcode, ctxt *context) error {171 buf := ctxt.buf.Next(ctxt.ptrSize)172 stack, err := util.ReadUintRaw(bytes.NewReader(buf), binary.LittleEndian, ctxt.ptrSize)173 if err != nil {174 return err175 }176 ctxt.stack = append(ctxt.stack, int64(stack+ctxt.StaticBase))177 return nil178}179func plusuconsts(opcode Opcode, ctxt *context) error {180 slen := len(ctxt.stack)181 num, _ := util.DecodeULEB128(ctxt.buf)182 ctxt.stack[slen-1] = ctxt.stack[slen-1] + int64(num)183 return nil184}185func consts(opcode Opcode, ctxt *context) error {186 num, _ := util.DecodeSLEB128(ctxt.buf)187 ctxt.stack = append(ctxt.stack, num)188 return nil189}190func framebase(opcode Opcode, ctxt *context) error {191 num, _ := util.DecodeSLEB128(ctxt.buf)192 ctxt.stack = append(ctxt.stack, ctxt.FrameBase+num)193 return nil194}195func register(opcode Opcode, ctxt *context) error {196 var regnum uint64197 if opcode == DW_OP_regx {198 regnum, _ = util.DecodeULEB128(ctxt.buf)199 } else {200 regnum = uint64(opcode - DW_OP_reg0)201 }202 return ctxt.closeLoc(opcode, Piece{Kind: RegPiece, Val: regnum})203}204func bregister(opcode Opcode, ctxt *context) error {205 var regnum uint64206 if opcode == DW_OP_bregx {207 regnum, _ = util.DecodeULEB128(ctxt.buf)208 } else {209 regnum = uint64(opcode - DW_OP_breg0)210 }211 offset, _ := util.DecodeSLEB128(ctxt.buf)212 if ctxt.Reg(regnum) == nil {213 return fmt.Errorf("register %d not available", regnum)214 }215 ctxt.stack = append(ctxt.stack, int64(ctxt.Uint64Val(regnum))+offset)216 return nil217}218func piece(opcode Opcode, ctxt *context) error {219 sz, _ := util.DecodeULEB128(ctxt.buf)220 if len(ctxt.stack) == 0 {221 // nothing on the stack means this piece is unavailable (padding,222 // optimized away...), see DWARFv4 sec. 2.6.1.3 page 30.223 ctxt.pieces = append(ctxt.pieces, Piece{Size: int(sz), Kind: ImmPiece, Val: 0})224 return nil225 }226 addr := ctxt.stack[len(ctxt.stack)-1]227 ctxt.pieces = append(ctxt.pieces, Piece{Size: int(sz), Kind: AddrPiece, Val: uint64(addr)})228 ctxt.stack = ctxt.stack[:0]229 return nil230}231func literal(opcode Opcode, ctxt *context) error {232 ctxt.stack = append(ctxt.stack, int64(opcode-DW_OP_lit0))233 return nil234}235func constnu(opcode Opcode, ctxt *context) error {236 var (237 n uint64238 err error239 )240 switch opcode {241 case DW_OP_const1u:242 var b uint8243 b, err = ctxt.buf.ReadByte()244 n = uint64(b)245 case DW_OP_const2u:246 n, err = util.ReadUintRaw(ctxt.buf, binary.LittleEndian, 2)247 case DW_OP_const4u:248 n, err = util.ReadUintRaw(ctxt.buf, binary.LittleEndian, 4)249 case DW_OP_const8u:250 n, err = util.ReadUintRaw(ctxt.buf, binary.LittleEndian, 8)251 default:252 panic("internal error")253 }254 if err != nil {255 return err256 }257 ctxt.stack = append(ctxt.stack, int64(n))258 return nil259}260func constns(opcode Opcode, ctxt *context) error {261 var (262 n uint64263 err error264 )265 switch opcode {266 case DW_OP_const1s:267 var b uint8268 b, err = ctxt.buf.ReadByte()269 n = uint64(int64(int8(b)))270 case DW_OP_const2s:271 n, err = util.ReadUintRaw(ctxt.buf, binary.LittleEndian, 2)272 n = uint64(int64(int16(n)))273 case DW_OP_const4s:274 n, err = util.ReadUintRaw(ctxt.buf, binary.LittleEndian, 4)275 n = uint64(int64(int32(n)))276 case DW_OP_const8s:277 n, err = util.ReadUintRaw(ctxt.buf, binary.LittleEndian, 8)278 default:279 panic("internal error")280 }281 if err != nil {282 return err283 }284 ctxt.stack = append(ctxt.stack, int64(n))285 return nil286}287func constu(opcode Opcode, ctxt *context) error {288 num, _ := util.DecodeULEB128(ctxt.buf)289 ctxt.stack = append(ctxt.stack, int64(num))290 return nil291}292func dup(_ Opcode, ctxt *context) error {293 if len(ctxt.stack) <= 0 {294 return ErrStackUnderflow295 }296 ctxt.stack = append(ctxt.stack, ctxt.stack[len(ctxt.stack)-1])297 return nil298}299func drop(_ Opcode, ctxt *context) error {300 if len(ctxt.stack) <= 0 {301 return ErrStackUnderflow302 }303 ctxt.stack = ctxt.stack[:len(ctxt.stack)-1]304 return nil305}306func pick(opcode Opcode, ctxt *context) error {307 var n byte308 switch opcode {309 case DW_OP_pick:310 n, _ = ctxt.buf.ReadByte()311 case DW_OP_over:312 n = 1313 default:314 panic("internal error")315 }316 idx := len(ctxt.stack) - 1 - int(uint8(n))317 if idx < 0 || idx >= len(ctxt.stack) {318 return ErrStackIndexOutOfBounds319 }320 ctxt.stack = append(ctxt.stack, ctxt.stack[idx])321 return nil322}323func swap(_ Opcode, ctxt *context) error {324 if len(ctxt.stack) < 2 {325 return ErrStackUnderflow326 }327 ctxt.stack[len(ctxt.stack)-1], ctxt.stack[len(ctxt.stack)-2] = ctxt.stack[len(ctxt.stack)-2], ctxt.stack[len(ctxt.stack)-1]328 return nil329}330func rot(_ Opcode, ctxt *context) error {331 if len(ctxt.stack) < 3 {332 return ErrStackUnderflow333 }334 ctxt.stack[len(ctxt.stack)-1], ctxt.stack[len(ctxt.stack)-2], ctxt.stack[len(ctxt.stack)-3] = ctxt.stack[len(ctxt.stack)-2], ctxt.stack[len(ctxt.stack)-3], ctxt.stack[len(ctxt.stack)-1]335 return nil336}337func unaryop(opcode Opcode, ctxt *context) error {338 if len(ctxt.stack) < 1 {339 return ErrStackUnderflow340 }341 operand := ctxt.stack[len(ctxt.stack)-1]342 switch opcode {343 case DW_OP_abs:344 if operand < 0 {345 operand = -operand346 }347 case DW_OP_neg:348 operand = -operand349 case DW_OP_not:350 operand = ^operand351 default:352 panic("internal error")353 }354 ctxt.stack[len(ctxt.stack)-1] = operand355 return nil356}357func binaryop(opcode Opcode, ctxt *context) error {358 if len(ctxt.stack) < 2 {359 return ErrStackUnderflow360 }361 second := ctxt.stack[len(ctxt.stack)-2]362 top := ctxt.stack[len(ctxt.stack)-1]363 var r int64364 ctxt.stack = ctxt.stack[:len(ctxt.stack)-2]365 switch opcode {366 case DW_OP_and:367 r = second & top368 case DW_OP_div:369 r = second / top370 case DW_OP_minus:371 r = second - top372 case DW_OP_mod:373 r = second % top374 case DW_OP_mul:375 r = second * top376 case DW_OP_or:377 r = second | top378 case DW_OP_plus:379 r = second + top380 case DW_OP_shl:381 r = second << uint64(top)382 case DW_OP_shr:383 r = second >> uint64(top)384 case DW_OP_shra:385 r = int64(uint64(second) >> uint64(top))386 case DW_OP_xor:387 r = second ^ top388 case DW_OP_le:389 r = bool2int(second <= top)390 case DW_OP_ge:391 r = bool2int(second >= top)392 case DW_OP_eq:393 r = bool2int(second == top)394 case DW_OP_lt:395 r = bool2int(second < top)396 case DW_OP_gt:397 r = bool2int(second > top)398 case DW_OP_ne:399 r = bool2int(second != top)400 default:401 panic("internal error")402 }403 ctxt.stack = append(ctxt.stack, r)404 return nil405}406func bool2int(b bool) int64 {407 if b {408 return 1409 }410 return 0411}412func (ctxt *context) jump(n int16) error {413 i := len(ctxt.prog) - ctxt.buf.Len() + int(n)414 if i < 0 {415 return ErrStackUnderflow416 }417 if i >= len(ctxt.prog) {418 i = len(ctxt.prog)419 }420 ctxt.buf = bytes.NewBuffer(ctxt.prog[i:])421 return nil422}423func skip(_ Opcode, ctxt *context) error {424 var n int16425 binary.Read(ctxt.buf, binary.LittleEndian, &n)426 return ctxt.jump(n)427}428func bra(_ Opcode, ctxt *context) error {429 var n int16430 binary.Read(ctxt.buf, binary.LittleEndian, &n)431 if len(ctxt.stack) < 1 {432 return ErrStackUnderflow433 }434 top := ctxt.stack[len(ctxt.stack)-1]435 ctxt.stack = ctxt.stack[:len(ctxt.stack)-1]436 if top != 0 {437 return ctxt.jump(n)438 }439 return nil440}441func stackvalue(_ Opcode, ctxt *context) error {442 if len(ctxt.stack) < 1 {443 return ErrStackUnderflow444 }445 val := ctxt.stack[len(ctxt.stack)-1]446 ctxt.stack = ctxt.stack[:len(ctxt.stack)-1]447 return ctxt.closeLoc(DW_OP_stack_value, Piece{Kind: ImmPiece, Val: uint64(val)})448}449func implicitvalue(_ Opcode, ctxt *context) error {450 sz, _ := util.DecodeULEB128(ctxt.buf)451 block := make([]byte, sz)452 n, _ := ctxt.buf.Read(block)453 if uint64(n) != sz {454 return fmt.Errorf("insufficient bytes read while reading DW_OP_implicit_value's block %d (expected: %d)", n, sz)455 }456 return ctxt.closeLoc(DW_OP_implicit_value, Piece{Kind: ImmPiece, Bytes: block, Size: int(sz)})457}458func deref(op Opcode, ctxt *context) error {459 if ctxt.readMemory == nil {460 return ErrMemoryReadUnavailable461 }462 sz := ctxt.ptrSize463 if op == DW_OP_deref_size || op == DW_OP_xderef_size {464 n, err := ctxt.buf.ReadByte()465 if err != nil {466 return err467 }468 sz = int(n)469 }470 if len(ctxt.stack) <= 0 {471 return ErrStackUnderflow472 }473 addr := ctxt.stack[len(ctxt.stack)-1]474 ctxt.stack = ctxt.stack[:len(ctxt.stack)-1]475 if op == DW_OP_xderef || op == DW_OP_xderef_size {476 if len(ctxt.stack) <= 0 {477 return ErrStackUnderflow478 }479 // the second element on the stack is the "address space identifier" which we don't do anything with480 ctxt.stack = ctxt.stack[:len(ctxt.stack)-1]481 }482 buf := make([]byte, sz)483 _, err := ctxt.readMemory(buf, uint64(addr))484 if err != nil {485 return err486 }487 x, err := util.ReadUintRaw(bytes.NewReader(buf), binary.LittleEndian, sz)488 if err != nil {489 return err490 }491 ctxt.stack = append(ctxt.stack, int64(x))492 return nil493}...

Full Screen

Full Screen

dwarf5_loclist.go

Source:dwarf5_loclist.go Github

copy

Full Screen

...5 "fmt"6 "github.com/go-delve/delve/pkg/dwarf/godwarf"7 "github.com/go-delve/delve/pkg/dwarf/util"8)9// Dwarf5Reader parses and presents DWARF loclist information for DWARF version 5 and later.10// See DWARFv5 section 7.29 page 243 and following.11type Dwarf5Reader struct {12 byteOrder binary.ByteOrder13 ptrSz int14 data []byte15}16func NewDwarf5Reader(data []byte) *Dwarf5Reader {17 if len(data) == 0 {18 return nil19 }20 r := &Dwarf5Reader{data: data}21 _, dwarf64, _, byteOrder := util.ReadDwarfLengthVersion(data)22 r.byteOrder = byteOrder23 data = data[6:]24 if dwarf64 {25 data = data[8:]26 }27 addrSz := data[0]28 segSelSz := data[1]29 r.ptrSz = int(addrSz + segSelSz)30 // Not read:31 // - offset_entry_count (4 bytes)32 // - offset table (offset_entry_count*4 or offset_entry_count*8 if dwarf64 is set)33 return r34}35func (rdr *Dwarf5Reader) Empty() bool {36 return rdr == nil37}38// Find returns the loclist entry for the specified PC address, inside the39// loclist stating at off. Base is the base address of the compile unit and40// staticBase is the static base at which the image is loaded.41func (rdr *Dwarf5Reader) Find(off int, staticBase, base, pc uint64, debugAddr *godwarf.DebugAddr) (*Entry, error) {42 it := &loclistsIterator{rdr: rdr, debugAddr: debugAddr, buf: bytes.NewBuffer(rdr.data), base: base, staticBase: staticBase}43 it.buf.Next(off)44 for it.next() {45 if !it.onRange {46 continue47 }48 if it.start <= pc && pc < it.end {49 return &Entry{it.start, it.end, it.instr}, nil50 }51 }52 if it.err != nil {53 return nil, it.err54 }55 if it.defaultInstr != nil {56 return &Entry{pc, pc + 1, it.defaultInstr}, nil57 }58 return nil, nil59}60type loclistsIterator struct {61 rdr *Dwarf5Reader62 debugAddr *godwarf.DebugAddr63 buf *bytes.Buffer64 staticBase uint6465 base uint64 // base for offsets in the list66 onRange bool67 atEnd bool68 start, end uint6469 instr []byte70 defaultInstr []byte71 err error72}73const (74 _DW_LLE_end_of_list uint8 = 0x075 _DW_LLE_base_addressx uint8 = 0x176 _DW_LLE_startx_endx uint8 = 0x277 _DW_LLE_startx_length uint8 = 0x378 _DW_LLE_offset_pair uint8 = 0x479 _DW_LLE_default_location uint8 = 0x580 _DW_LLE_base_address uint8 = 0x681 _DW_LLE_start_end uint8 = 0x782 _DW_LLE_start_length uint8 = 0x883)84func (it *loclistsIterator) next() bool {85 if it.err != nil || it.atEnd {86 return false87 }88 opcode, err := it.buf.ReadByte()89 if err != nil {90 it.err = err91 return false92 }93 switch opcode {94 case _DW_LLE_end_of_list:95 it.atEnd = true96 it.onRange = false97 return false98 case _DW_LLE_base_addressx:99 baseIdx, _ := util.DecodeULEB128(it.buf)100 if err != nil {101 it.err = err102 return false103 }104 it.base, it.err = it.debugAddr.Get(baseIdx)105 it.base += it.staticBase106 it.onRange = false107 case _DW_LLE_startx_endx:108 startIdx, _ := util.DecodeULEB128(it.buf)109 endIdx, _ := util.DecodeULEB128(it.buf)110 it.readInstr()111 it.start, it.err = it.debugAddr.Get(startIdx)112 if it.err == nil {113 it.end, it.err = it.debugAddr.Get(endIdx)114 }115 it.onRange = true116 case _DW_LLE_startx_length:117 startIdx, _ := util.DecodeULEB128(it.buf)118 length, _ := util.DecodeULEB128(it.buf)119 it.readInstr()120 it.start, it.err = it.debugAddr.Get(startIdx)121 it.end = it.start + length122 it.onRange = true123 case _DW_LLE_offset_pair:124 off1, _ := util.DecodeULEB128(it.buf)125 off2, _ := util.DecodeULEB128(it.buf)126 it.readInstr()127 it.start = it.base + off1128 it.end = it.base + off2129 it.onRange = true130 case _DW_LLE_default_location:131 it.readInstr()132 it.defaultInstr = it.instr133 it.onRange = false134 case _DW_LLE_base_address:135 it.base, it.err = util.ReadUintRaw(it.buf, it.rdr.byteOrder, it.rdr.ptrSz)136 it.base += it.staticBase137 it.onRange = false138 case _DW_LLE_start_end:139 it.start, it.err = util.ReadUintRaw(it.buf, it.rdr.byteOrder, it.rdr.ptrSz)140 it.end, it.err = util.ReadUintRaw(it.buf, it.rdr.byteOrder, it.rdr.ptrSz)141 it.readInstr()142 it.onRange = true143 case _DW_LLE_start_length:144 it.start, it.err = util.ReadUintRaw(it.buf, it.rdr.byteOrder, it.rdr.ptrSz)145 length, _ := util.DecodeULEB128(it.buf)146 it.readInstr()147 it.end = it.start + length148 it.onRange = true149 default:150 it.err = fmt.Errorf("unknown opcode %#x at %#x", opcode, len(it.rdr.data)-it.buf.Len())151 it.onRange = false152 it.atEnd = true153 return false154 }155 return true156}157func (it *loclistsIterator) readInstr() {158 length, _ := util.DecodeULEB128(it.buf)...

Full Screen

Full Screen

ioutil.go

Source:ioutil.go Github

copy

Full Screen

...4 "errors"5 "io"6 "github.com/amitbet/teleporter/logger"7)8func ReadUint32(r io.Reader) (uint32, error) {9 var myUint uint3210 if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {11 return 0, err12 }13 return myUint, nil14}15func ReadUint8(r io.Reader) (uint8, error) {16 var myUint uint817 if err := binary.Read(r, binary.BigEndian, &myUint); err != nil {18 return 0, err19 }20 return myUint, nil21}22func ReadBytes(r io.Reader, count int) ([]byte, error) {23 buff := make([]byte, count)24 lengthRead, err := io.ReadFull(r, buff)25 if lengthRead != count {26 logger.Errorf("util.ReadBytes unable to read bytes: lengthRead=%d, countExpected=%d", lengthRead, count)27 return nil, errors.New("util.ReadBytes unable to read bytes")28 }29 if err != nil {30 logger.Errorf("util.ReadBytes error while reading bytes: ", err)31 return nil, err32 }33 return buff, nil34}35func ReadString(r io.Reader) (string, error) {36 size, err := ReadUint32(r)37 if err != nil {38 logger.Errorf("util.ReadString error while reading string size: ", err)39 return "", err40 }41 bytes, err := ReadBytes(r, int(size))42 if err != nil {43 logger.Errorf("util.ReadString error while reading string: ", err)44 return "", err45 }46 return string(bytes), nil47}48func WriteString(w io.Writer, str string) error {49 length := uint32(len(str))50 err := binary.Write(w, binary.BigEndian, length)51 if err != nil {52 logger.Errorf("util.WriteString error while writeing string length: ", err)53 return err54 }55 written, err := w.Write([]byte(str))56 if err != nil {57 logger.Errorf("util.WriteString error while writeing string: ", err)58 return err59 }60 if written != int(length) {61 logger.Errorf("util.WriteString error while writeing string: ", err)62 return errors.New("util.WriteString error while writeing string: written size too small")63 }64 return nil65}66func ReadShortString(r io.Reader) (string, error) {67 size, err := ReadUint8(r)68 if err != nil {69 logger.Errorf("util.ReadShortString error while reading string size: ", err)70 return "", err71 }72 bytes, err := ReadBytes(r, int(size))73 if err != nil {74 logger.Errorf("util.ReadShortString error while reading string: ", err)75 return "", err76 }77 return string(bytes), nil78}79func WriteShortString(w io.Writer, str string) error {80 length := uint8(len(str))81 err := binary.Write(w, binary.BigEndian, length)82 if err != nil {83 logger.Errorf("util.WriteShortString error while writeing string length: ", err)84 return err85 }86 written, err := w.Write([]byte(str))87 if err != nil {88 logger.Errorf("util.WriteShortString error while writeing string: ", err)...

Full Screen

Full Screen

Read

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 a, b, err = util.Read()4 if err != nil {5 fmt.Println(err)6 } else {7 fmt.Println("a = ", a, "b = ", b)8 }9}10import (11func main() {12 a, b, err = util.Read()13 if err != nil {14 fmt.Println(err)15 } else {16 fmt.Println("a = ", a, "b = ", b)17 }18}19import (20func main() {21 a, b, err = util.Read()22 if err != nil {23 fmt.Println(err)24 } else {25 fmt.Println("a = ", a, "b = ", b)26 }27}28import "fmt"29func Read() (int, int, error) {30 fmt.Println("Enter a")31 _, err = fmt.Scanln(&a)32 if err != nil {33 }34 fmt.Println("Enter b")35 _, err = fmt.Scanln(&b)36 if err != nil {37 }38}

Full Screen

Full Screen

Read

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("x = ", x)4 x.Read()5 fmt.Println("x = ", x)6}

Full Screen

Full Screen

Read

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World!")4 fmt.Println(util.Read())5}6import (7func main() {8 fmt.Println("Hello World!")9 util.Write()10}11import (12func main() {13 fmt.Println("Hello World!")14 fmt.Println(util.Add(1,2))15}16import (17func main() {18 fmt.Println("Hello World!")19 fmt.Println(util.Add(1,2))20}21import (22func main() {23 fmt.Println("Hello World!")24 fmt.Println(util.Add(1,2))25}26import (27func main() {28 fmt.Println("Hello World!")29 fmt.Println(util.Add(1,2))30}

Full Screen

Full Screen

Read

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter a string")4 fmt.Scanln(&str)5 Utility.Read(str)6}

Full Screen

Full Screen

Read

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(util.Read())4}5import (6func main() {7 fmt.Println(util.Write())8}9import (10func main() {11 fmt.Println(util.Read())12 fmt.Println(util.Write())13}14import (15func main() {16 fmt.Println(util.Read())17 fmt.Println(util.Write())18}19import (20func main() {21 fmt.Println(util.Read())22 fmt.Println(util.Write())23}24import (25func main() {26 fmt.Println(util.Read())27 fmt.Println(util.Write())28}29import (30func main() {31 fmt.Println(util.Read())32 fmt.Println(util.Write())33}34import (35func main() {36 fmt.Println(util.Read())37 fmt.Println(util.Write())38}39import (

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful