How to use unmarshal method of types Package

Best K6 code snippet using types.unmarshal

activity.go

Source:activity.go Github

copy

Full Screen

...49 Data json.RawMessage `json:"data"`50 } `json:"actor"`51 } `json:"relationships"`52}53// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.54func (a *Activity) UnmarshalJSON(b []byte) error {55 var helper activityUnmarshalHelper56 helper.Attributes = &helper.activity57 if err := json.Unmarshal(b, &helper); err != nil {58 return err59 }60 *a = Activity(helper.activity)61 a.Attachments = helper.Relationships.Attachments.Data62 a.RawActor = helper.Relationships.RawActor.Data63 a.rawData = b64 return nil65}66// Actor returns returns the parsed actor. For recognized actor types, a value of the corresponding struct type will be returned.67func (a *Activity) Actor() (actor interface{}) {68 var obj unknownResource69 if err := json.Unmarshal(a.RawActor, &obj); err != nil {70 panic(err.Error())71 }72 switch *obj.Type {73 case UserType:74 actor = &User{}75 case ProgramType:76 actor = &Program{}77 }78 if err := json.Unmarshal(a.RawActor, &actor); err != nil {79 panic(err.Error())80 }81 return actor82}83// Activity returns the parsed activity. For recognized activity types, a value of the corresponding struct type will be returned.84func (a *Activity) Activity() (activity interface{}) {85 switch *a.Type {86 case ActivityBountyAwardedType:87 activity = &ActivityBountyAwarded{}88 case ActivityBountySuggestedType:89 activity = &ActivityBountySuggested{}90 case ActivityBugClonedType:91 activity = &ActivityBugCloned{}92 case ActivityExternalUserInvitationCancelledType:93 activity = &ActivityExternalUserInvitationCancelled{}94 case ActivityExternalUserInvitedType:95 activity = &ActivityExternalUserInvited{}96 case ActivityExternalUserJoinedType:97 activity = &ActivityExternalUserJoined{}98 case ActivityExternalUserRemovedType:99 activity = &ActivityExternalUserRemoved{}100 case ActivityGroupAssignedToBugType:101 activity = &ActivityGroupAssignedToBug{}102 case ActivityReferenceIDAddedType:103 activity = &ActivityReferenceIDAdded{}104 case ActivityReportTitleUpdatedType:105 activity = &ActivityReportTitleUpdated{}106 case ActivityReportVulnerabilityTypesUpdatedType:107 activity = &ActivityReportVulnerabilityTypesUpdated{}108 case ActivitySwagAwardedType:109 activity = &ActivitySwagAwarded{}110 case ActivityUserAssignedToBugType:111 activity = &ActivityUserAssignedToBug{}112 case ActivityUserBannedFromProgramType:113 activity = &ActivityUserBannedFromProgram{}114 default:115 return nil116 }117 if err := json.Unmarshal(a.rawData, activity); err != nil {118 panic(err.Error())119 }120 return activity121}122// Report returns the report this activity is a child of123func (a *Activity) Report() *Report {124 return a.report125}126// ActivityBountyAwarded occurs when a bounty is awarded.127//128// HackerOne API docs:https://api.hackerone.com/docs/v1#activity-bounty-awarded129type ActivityBountyAwarded struct {130 BountyAmount *string `json:"bounty_amount"`131 BonusAmount *string `json:"bonus_amount"`132}133// Helper types for JSONUnmarshal134type activityBountyAwarded ActivityBountyAwarded // Used to avoid recursion of JSONUnmarshal135type activityBountyAwardedUnmarshalHelper struct {136 Attributes activityBountyAwarded `json:"attributes"`137}138// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.139func (a *ActivityBountyAwarded) UnmarshalJSON(b []byte) error {140 var helper activityBountyAwardedUnmarshalHelper141 if err := json.Unmarshal(b, &helper); err != nil {142 return err143 }144 *a = ActivityBountyAwarded(helper.Attributes)145 return nil146}147// ActivityBountySuggested occurs when a bounty is suggested.148//149// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-bounty-suggested150type ActivityBountySuggested struct {151 BountyAmount *string `json:"bounty_amount"`152 BonusAmount *string `json:"bonus_amount"`153}154// Helper types for JSONUnmarshal155type activityBountySuggested ActivityBountySuggested // Used to avoid recursion of JSONUnmarshal156type activityBountySuggestedUnmarshalHelper struct {157 Attributes activityBountySuggested `json:"attributes"`158}159// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.160func (a *ActivityBountySuggested) UnmarshalJSON(b []byte) error {161 var helper activityBountySuggestedUnmarshalHelper162 if err := json.Unmarshal(b, &helper); err != nil {163 return err164 }165 *a = ActivityBountySuggested(helper.Attributes)166 return nil167}168// ActivityBugCloned occurs when a bug is cloned.169//170// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-bug-cloned171type ActivityBugCloned struct {172 OriginalReportID *int `json:"original_report_id"`173}174// Helper types for JSONUnmarshal175type activityBugCloned ActivityBugCloned // Used to avoid recursion of JSONUnmarshal176type activityBugClonedUnmarshalHelper struct {177 Attributes activityBugCloned `json:"attributes"`178}179// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.180func (a *ActivityBugCloned) UnmarshalJSON(b []byte) error {181 var helper activityBugClonedUnmarshalHelper182 if err := json.Unmarshal(b, &helper); err != nil {183 return err184 }185 *a = ActivityBugCloned(helper.Attributes)186 return nil187}188// ActivityExternalUserInvitationCancelled occurs when a external user's invitiation is cancelled.189//190// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-external-user-invitation-cancelled191type ActivityExternalUserInvitationCancelled struct {192 Email *string `json:"email"`193}194// Helper types for JSONUnmarshal195type activityExternalUserInvitationCancelled ActivityExternalUserInvitationCancelled // Used to avoid recursion of JSONUnmarshal196type activityExternalUserInvitationCancelledSuggestedUnmarshalHelper struct {197 Attributes activityExternalUserInvitationCancelled `json:"attributes"`198}199// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.200func (a *ActivityExternalUserInvitationCancelled) UnmarshalJSON(b []byte) error {201 var helper activityExternalUserInvitationCancelledSuggestedUnmarshalHelper202 if err := json.Unmarshal(b, &helper); err != nil {203 return err204 }205 *a = ActivityExternalUserInvitationCancelled(helper.Attributes)206 return nil207}208// ActivityExternalUserInvited occurs when a external user is invited.209//210// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-external-user-invited211type ActivityExternalUserInvited struct {212 Email *string `json:"email"`213}214// Helper types for JSONUnmarshal215type activityExternalUserInvited ActivityExternalUserInvited // Used to avoid recursion of JSONUnmarshal216type activityExternalUserInvitedUnmarshalHelper struct {217 Attributes activityExternalUserInvited `json:"attributes"`218}219// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.220func (a *ActivityExternalUserInvited) UnmarshalJSON(b []byte) error {221 var helper activityExternalUserInvitedUnmarshalHelper222 if err := json.Unmarshal(b, &helper); err != nil {223 return err224 }225 *a = ActivityExternalUserInvited(helper.Attributes)226 return nil227}228// ActivityExternalUserJoined occurs when a external user joins.229//230// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-external-user-joined231type ActivityExternalUserJoined struct {232 DuplicateReportID *int `json:"duplicate_report_id"`233}234// Helper types for JSONUnmarshal235type activityExternalUserJoined ActivityExternalUserJoined // Used to avoid recursion of JSONUnmarshal236type activityExternalUserJoinedUnmarshalHelper struct {237 Attributes activityExternalUserJoined `json:"attributes"`238}239// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.240func (a *ActivityExternalUserJoined) UnmarshalJSON(b []byte) error {241 var helper activityExternalUserJoinedUnmarshalHelper242 if err := json.Unmarshal(b, &helper); err != nil {243 return err244 }245 *a = ActivityExternalUserJoined(helper.Attributes)246 return nil247}248// ActivityExternalUserRemoved occurs when a external user is removed249//250// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-external-user-removed251type ActivityExternalUserRemoved struct {252 RemovedUser *User `json:"removed_user"`253}254// Helper types for JSONUnmarshal255type activityExternalUserRemoved ActivityExternalUserRemoved // Used to avoid recursion of JSONUnmarshal256type activityExternalUserRemovedUnmarshalHelper struct {257 Relationships struct {258 RemovedUser struct {259 Data *User `json:"data"`260 } `json:"removed_user"`261 } `json:"relationships"`262}263// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.264func (a *ActivityExternalUserRemoved) UnmarshalJSON(b []byte) error {265 var helper activityExternalUserRemovedUnmarshalHelper266 if err := json.Unmarshal(b, &helper); err != nil {267 return err268 }269 a.RemovedUser = helper.Relationships.RemovedUser.Data270 return nil271}272// ActivityGroupAssignedToBug occurs when a group is assigned to a report.273//274// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-group-assigned-to-bug275type ActivityGroupAssignedToBug struct {276 Group *Group `json:"group"`277}278// Helper types for JSONUnmarshal279type activityGroupAssignedToBug ActivityGroupAssignedToBug // Used to avoid recursion of JSONUnmarshal280type activityGroupAssignedToBugUnmarshalHelper struct {281 Relationships struct {282 Group struct {283 Data *Group `json:"data"`284 } `json:"group"`285 } `json:"relationships"`286}287// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.288func (a *ActivityGroupAssignedToBug) UnmarshalJSON(b []byte) error {289 var helper activityGroupAssignedToBugUnmarshalHelper290 if err := json.Unmarshal(b, &helper); err != nil {291 return err292 }293 a.Group = helper.Relationships.Group.Data294 return nil295}296// ActivityReferenceIDAdded occurs when a reference id/url is added to a report.297//298// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-reference-id-added299type ActivityReferenceIDAdded struct {300 Reference *string `json:"reference"`301 ReferenceURL *string `json:"reference_url"`302}303// Helper types for JSONUnmarshal304type activityReferenceIDAdded ActivityReferenceIDAdded // Used to avoid recursion of JSONUnmarshal305type activityReferenceIDAddedUnmarshalHelper struct {306 Attributes activityReferenceIDAdded `json:"attributes"`307}308// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.309func (a *ActivityReferenceIDAdded) UnmarshalJSON(b []byte) error {310 var helper activityReferenceIDAddedUnmarshalHelper311 if err := json.Unmarshal(b, &helper); err != nil {312 return err313 }314 *a = ActivityReferenceIDAdded(helper.Attributes)315 return nil316}317// ActivityReportTitleUpdated occurs when report title is updated318//319// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-report-title-updated320type ActivityReportTitleUpdated struct {321 OldTitle *string `json:"old_title"`322 NewTitle *string `json:"new_title"`323}324// Helper types for JSONUnmarshal325type activityReportTitleUpdated ActivityReportTitleUpdated // Used to avoid recursion of JSONUnmarshal326type activityReportTitleUpdatedUnmarshalHelper struct {327 Attributes activityReportTitleUpdated `json:"attributes"`328}329// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.330func (a *ActivityReportTitleUpdated) UnmarshalJSON(b []byte) error {331 var helper activityReportTitleUpdatedUnmarshalHelper332 if err := json.Unmarshal(b, &helper); err != nil {333 return err334 }335 *a = ActivityReportTitleUpdated(helper.Attributes)336 return nil337}338// ActivityReportVulnerabilityTypesUpdated occurs when vulnerability types for a report are updated.339//340// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-report-vulnerability-types-updated341type ActivityReportVulnerabilityTypesUpdated struct {342 OldVulnerabilityTypes []VulnerabilityType `json:"old_vulnerability_types"`343 NewVulnerabilityTypes []VulnerabilityType `json:"new_vulnerability_types"`344}345// Helper types for JSONUnmarshal346type activityReportVulnerabilityTypesUpdated ActivityReportVulnerabilityTypesUpdated // Used to avoid recursion of JSONUnmarshal347type activityReportVulnerabilityTypesUpdatedUnmarshalHelper struct {348 Relationships struct {349 OldVulnerabilityTypes struct {350 Data []VulnerabilityType `json:"data"`351 } `json:"old_vulnerability_types"`352 NewVulnerabilityTypes struct {353 Data []VulnerabilityType `json:"data"`354 } `json:"new_vulnerability_types"`355 } `json:"relationships"`356}357// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.358func (a *ActivityReportVulnerabilityTypesUpdated) UnmarshalJSON(b []byte) error {359 var helper activityReportVulnerabilityTypesUpdatedUnmarshalHelper360 if err := json.Unmarshal(b, &helper); err != nil {361 return err362 }363 a.OldVulnerabilityTypes = helper.Relationships.OldVulnerabilityTypes.Data364 a.NewVulnerabilityTypes = helper.Relationships.NewVulnerabilityTypes.Data365 return nil366}367// ActivitySwagAwarded occurs when swag is awarded368//369// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-swag-awarded370type ActivitySwagAwarded struct {371 Swag *Swag `json:"swag"`372}373// Helper types for JSONUnmarshal374type activitySwagAwarded ActivitySwagAwarded // Used to avoid recursion of JSONUnmarshal375type activitySwagAwardedUnmarshalHelper struct {376 Relationships struct {377 Swag struct {378 Data *Swag `json:"data"`379 } `json:"swag"`380 } `json:"relationships"`381}382// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.383func (a *ActivitySwagAwarded) UnmarshalJSON(b []byte) error {384 var helper activitySwagAwardedUnmarshalHelper385 if err := json.Unmarshal(b, &helper); err != nil {386 return err387 }388 a.Swag = helper.Relationships.Swag.Data389 return nil390}391// ActivityUserAssignedToBug occurs when a user is assigned to a report.392//393// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-user-assigned-to-bug394type ActivityUserAssignedToBug struct {395 AssignedUser *User `json:"assigned_user"`396}397// Helper types for JSONUnmarshal398type activityUserAssignedToBug ActivityUserAssignedToBug // Used to avoid recursion of JSONUnmarshal399type activityUserAssignedToBugUnmarshalHelper struct {400 Relationships struct {401 AssignedUser struct {402 Data *User `json:"data"`403 } `json:"assigned_user"`404 } `json:"relationships"`405}406// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.407func (a *ActivityUserAssignedToBug) UnmarshalJSON(b []byte) error {408 var helper activityUserAssignedToBugUnmarshalHelper409 if err := json.Unmarshal(b, &helper); err != nil {410 return err411 }412 a.AssignedUser = helper.Relationships.AssignedUser.Data413 return nil414}415// ActivityUserBannedFromProgram occurs when a user is banned from a program.416//417// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-user-banned-from-program418type ActivityUserBannedFromProgram struct {419 RemovedUser *User `json:"removed_user"`420}421// Helper types for JSONUnmarshal422type activityUserBannedFromProgram ActivityUserBannedFromProgram // Used to avoid recursion of JSONUnmarshal423type activityUserBannedFromProgramUnmarshalHelper struct {424 Relationships struct {425 RemovedUser struct {426 Data *User `json:"data"`427 } `json:"removed_user"`428 } `json:"relationships"`429}430// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.431func (a *ActivityUserBannedFromProgram) UnmarshalJSON(b []byte) error {432 var helper activityUserBannedFromProgramUnmarshalHelper433 if err := json.Unmarshal(b, &helper); err != nil {434 return err435 }436 a.RemovedUser = helper.Relationships.RemovedUser.Data437 return nil438}...

Full Screen

Full Screen

log.go

Source:log.go Github

copy

Full Screen

...10}11func UnmarshalGoroutine(buf []byte, g *types.Goroutine) int64 {12 var total int6413 var n int6414 g.GID, n = unmarshalGID(buf)15 total += n16 g.StartTime, n = unmarshalTime(buf[total:])17 total += n18 g.EndTime, n = unmarshalTime(buf[total:])19 total += n20 return total21}22func SizeGoroutine() int64 {23 var total int6424 total += 8 * 3 // 8byteのフィールドが3個 (GID, StartTime, EndTime)25 return total26}27func MarshalFuncLog(buf []byte, f *types.FuncLog) int64 {28 total := marshalFuncLogID(buf, f.ID)29 total += marshalTime(buf[total:], f.StartTime)30 total += marshalTime(buf[total:], f.EndTime)31 total += marshalFuncLogID(buf[total:], f.ParentID)32 total += marshalUintptrSlice(buf[total:], f.Frames)33 total += marshalGID(buf[total:], f.GID)34 return total35}36// fl.Frames には十分なサイズのバッファが容易されて無ければならない。37func UnmarshalFuncLog(buf []byte, f *types.FuncLog) int64 {38 var total int6439 var n int6440 f.ID, n = unmarshalFuncLogID(buf)41 total += n42 f.StartTime, n = unmarshalTime(buf[total:])43 total += n44 f.EndTime, n = unmarshalTime(buf[total:])45 total += n46 f.ParentID, n = unmarshalFuncLogID(buf[total:])47 total += n48 total += unmarshalUintptrSlice(buf[total:], &f.Frames)49 f.GID, n = unmarshalGID(buf[total:])50 total += n51 return total52}53func SizeFuncLog() int64 {54 var total int6455 total += 8 * 5 // 8byteのフィールドが5個 (ID, StartTime, EndTime, ParentID, GID)56 total += 8 * (1 + types.MaxStackSize) // スライスが1個 (Frames)57 return total58}59func MarshalRawFuncLog(buf []byte, r *types.RawFuncLog) int64 {60 total := marshalRawFuncLogID(buf, r.ID)61 total += marshalTagName(buf[total:], r.Tag)62 total += marshalTime(buf[total:], r.Timestamp)63 total += marshalUintptrSlice(buf[total:], r.Frames)64 total += marshalGID(buf[total:], r.GID)65 total += marshalTxID(buf[total:], r.TxID)66 return total67}68// fl.Frames には十分なサイズのバッファが容易されて無ければならない。69func UnmarshalRawFuncLog(buf []byte, r *types.RawFuncLog) int64 {70 var total int6471 var n int6472 r.ID, n = unmarshalRawFuncLogID(buf)73 total += n74 r.Tag, n = unmarshalTagName(buf[total:])75 total += n76 r.Timestamp, n = unmarshalTime(buf[total:])77 total += n78 total += unmarshalUintptrSlice(buf[total:], &r.Frames)79 r.GID, n = unmarshalGID(buf[total:])80 total += n81 r.TxID, n = unmarshalTxID(buf[total:])82 total += n83 return total84}85func SizeRawFuncLog() int64 {86 var total int6487 total += 8 * 4 // 8byteのフィールドが4個 (ID, Timestamp, GID, TxID)88 total += 1 // 1byteのフィールドが1個 (Tag)89 total += 8 * (1 + types.MaxStackSize) // スライスが1個 (Frames)90 return total91}92func marshalGoModule(buf []byte, mod types.GoModule) int64 {93 var total int6494 total += MarshalString(buf[total:], mod.Name)95 total += MarshalUintptr(buf[total:], mod.MinPC)96 total += MarshalUintptr(buf[total:], mod.MaxPC)97 return total98}99func unmarshalGoModule(buf []byte) (types.GoModule, int64) {100 var total int64101 var n int64102 var mod types.GoModule103 mod.Name, n = UnmarshalString(buf[total:])104 total += n105 mod.MinPC, n = UnmarshalUintptr(buf[total:])106 total += n107 mod.MaxPC, n = UnmarshalUintptr(buf[total:])108 total += n109 return mod, total110}111func sizeGoModule(mod types.GoModule) int64 {112 total := sizeString(mod.Name) // Name113 total += 8 // MinPC114 total += 8 // MaxPC115 return total116}117func marshalGoModuleSlice(buf []byte, mods []types.GoModule) int64 {118 var total int64119 n := MarshalUint64(buf[total:], uint64(len(mods)))120 total += n121 for i := range mods {122 n = marshalGoModule(buf[total:], mods[i])123 total += n124 }125 return total126}127func unmarshalGoModuleSlice(buf []byte) ([]types.GoModule, int64) {128 var total int64129 length, n := UnmarshalUint64(buf)130 total += n131 mods := make([]types.GoModule, length)132 for i := range mods {133 mods[i], n = unmarshalGoModule(buf[total:])134 total += n135 }136 return mods, total137}138func sizeGoModuleSlice(mods []types.GoModule) int64 {139 total := int64(8) // 8 is bytes of slice length (int64)140 for i := range mods {141 total += sizeGoModule(mods[i])142 }143 return total144}145func marshalGoFunc(buf []byte, s types.GoFunc) int64 {146 var total int64147 total += MarshalString(buf[total:], s.Name)148 total += MarshalUint64(buf[total:], uint64(s.Entry))149 return total150}151func unmarshalGoFunc(buf []byte) (types.GoFunc, int64) {152 var total int64153 var n int64154 s := types.GoFunc{}155 total += n156 s.Name, n = UnmarshalString(buf[total:])157 total += n158 ptr, n := UnmarshalUint64(buf[total:])159 total += n160 s.Entry = uintptr(ptr)161 return s, total162}163func sizeGoFunc(fn types.GoFunc) int64 {164 total := int64(8) // Entry165 total += sizeString(fn.Name) // Name166 return total167}168func marshalGoFuncSlice(buf []byte, funcs []types.GoFunc) int64 {169 var total int64170 n := MarshalUint64(buf[total:], uint64(len(funcs)))171 total += n172 for i := range funcs {173 n = marshalGoFunc(buf[total:], funcs[i])174 total += n175 }176 return total177}178func unmarshalGoFuncSlice(buf []byte) ([]types.GoFunc, int64) {179 var total int64180 length, n := UnmarshalUint64(buf)181 total += n182 funcs := make([]types.GoFunc, length)183 for i := range funcs {184 funcs[i], n = unmarshalGoFunc(buf[total:])185 total += n186 }187 return funcs, total188}189func sizeGoFuncSlice(funcs []types.GoFunc) int64 {190 total := int64(8) // slice length191 for i := range funcs {192 total += sizeGoFunc(funcs[i])193 }194 return total195}196func marshalGoLine(buf []byte, s types.GoLine) int64 {197 var total int64198 total += MarshalUintptr(buf[total:], s.PC)199 total += marshalFileID(buf[total:], s.FileID)200 total += marshalUint32(buf[total:], s.Line)201 return total202}203func unmarshalGoLine(buf []byte) (types.GoLine, int64) {204 var total int64205 var n int64206 s := types.GoLine{}207 s.PC, n = UnmarshalUintptr(buf[total:])208 total += n209 s.FileID, n = unmarshalFileID(buf[total:])210 total += n211 s.Line, n = unmarshalUint32(buf[total:])212 total += n213 return s, total214}215func sizeGoLine(line types.GoLine) int64 {216 total := int64(8) // PC217 total += sizeFileID() // FileID218 total += 4 // Line219 return total220}221func marshalGoLineSlice(buf []byte, line []types.GoLine) int64 {222 total := MarshalUint64(buf, uint64(len(line)))223 for i := range line {224 total += marshalGoLine(buf[total:], line[i])225 }226 return total227}228func unmarshalGoLineSlice(buf []byte) ([]types.GoLine, int64) {229 var total int64230 length, n := UnmarshalUint64(buf)231 total += n232 line := make([]types.GoLine, length)233 for i := range line {234 line[i], n = unmarshalGoLine(buf[total:])235 total += n236 }237 return line, total238}239func sizeGoLineSlice(lines []types.GoLine) int64 {240 total := int64(8) // slice length241 for i := range lines {242 total += sizeGoLine(lines[i])243 }244 return total245}...

Full Screen

Full Screen

PAData.go

Source:PAData.go Github

copy

Full Screen

1package types2// Reference: https://www.ietf.org/rfc/rfc4120.txt3// Section: 5.2.74import (5 "fmt"6 "time"7 "github.com/jcmturner/gofork/encoding/asn1"8 "gopkg.in/jcmturner/gokrb5.v7/iana/patype"9)10// PAData implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.711type PAData struct {12 PADataType int32 `asn1:"explicit,tag:1"`13 PADataValue []byte `asn1:"explicit,tag:2"`14}15// PADataSequence implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.716type PADataSequence []PAData17// MethodData implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.9.118type MethodData []PAData19// PAEncTimestamp implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7.220type PAEncTimestamp EncryptedData21// PAEncTSEnc implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7.222type PAEncTSEnc struct {23 PATimestamp time.Time `asn1:"generalized,explicit,tag:0"`24 PAUSec int `asn1:"explicit,optional,tag:1"`25}26// Contains tests if a PADataSequence contains PA Data of a certain type.27func (pas *PADataSequence) Contains(patype int32) bool {28 for _, pa := range *pas {29 if pa.PADataType == patype {30 return true31 }32 }33 return false34}35// GetPAEncTSEncAsnMarshalled returns the bytes of a PAEncTSEnc.36func GetPAEncTSEncAsnMarshalled() ([]byte, error) {37 t := time.Now().UTC()38 p := PAEncTSEnc{39 PATimestamp: t,40 PAUSec: int((t.UnixNano() / int64(time.Microsecond)) - (t.Unix() * 1e6)),41 }42 b, err := asn1.Marshal(p)43 if err != nil {44 return b, fmt.Errorf("error mashaling PAEncTSEnc: %v", err)45 }46 return b, nil47}48// ETypeInfoEntry implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7.449type ETypeInfoEntry struct {50 EType int32 `asn1:"explicit,tag:0"`51 Salt []byte `asn1:"explicit,optional,tag:1"`52}53// ETypeInfo implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7.454type ETypeInfo []ETypeInfoEntry55// ETypeInfo2Entry implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7.556type ETypeInfo2Entry struct {57 EType int32 `asn1:"explicit,tag:0"`58 Salt string `asn1:"explicit,optional,generalstring,tag:1"`59 S2KParams []byte `asn1:"explicit,optional,tag:2"`60}61// ETypeInfo2 implements RFC 4120 types: https://tools.ietf.org/html/rfc4120#section-5.2.7.562type ETypeInfo2 []ETypeInfo2Entry63// PAReqEncPARep PA Data Type64type PAReqEncPARep struct {65 ChksumType int32 `asn1:"explicit,tag:0"`66 Chksum []byte `asn1:"explicit,tag:1"`67}68// Unmarshal bytes into the PAData69func (pa *PAData) Unmarshal(b []byte) error {70 _, err := asn1.Unmarshal(b, pa)71 return err72}73// Unmarshal bytes into the PADataSequence74func (pas *PADataSequence) Unmarshal(b []byte) error {75 _, err := asn1.Unmarshal(b, pas)76 return err77}78// Unmarshal bytes into the PAReqEncPARep79func (pa *PAReqEncPARep) Unmarshal(b []byte) error {80 _, err := asn1.Unmarshal(b, pa)81 return err82}83// Unmarshal bytes into the PAEncTimestamp84func (pa *PAEncTimestamp) Unmarshal(b []byte) error {85 _, err := asn1.Unmarshal(b, pa)86 return err87}88// Unmarshal bytes into the PAEncTSEnc89func (pa *PAEncTSEnc) Unmarshal(b []byte) error {90 _, err := asn1.Unmarshal(b, pa)91 return err92}93// Unmarshal bytes into the ETypeInfo94func (a *ETypeInfo) Unmarshal(b []byte) error {95 _, err := asn1.Unmarshal(b, a)96 return err97}98// Unmarshal bytes into the ETypeInfoEntry99func (a *ETypeInfoEntry) Unmarshal(b []byte) error {100 _, err := asn1.Unmarshal(b, a)101 return err102}103// Unmarshal bytes into the ETypeInfo2104func (a *ETypeInfo2) Unmarshal(b []byte) error {105 _, err := asn1.Unmarshal(b, a)106 return err107}108// Unmarshal bytes into the ETypeInfo2Entry109func (a *ETypeInfo2Entry) Unmarshal(b []byte) error {110 _, err := asn1.Unmarshal(b, a)111 return err112}113// GetETypeInfo returns an ETypeInfo from the PAData.114func (pa *PAData) GetETypeInfo() (d ETypeInfo, err error) {115 if pa.PADataType != patype.PA_ETYPE_INFO {116 err = fmt.Errorf("PAData does not contain PA EType Info data. TypeID Expected: %v; Actual: %v", patype.PA_ETYPE_INFO, pa.PADataType)117 return118 }119 _, err = asn1.Unmarshal(pa.PADataValue, &d)120 return121}122// GetETypeInfo2 returns an ETypeInfo2 from the PAData.123func (pa *PAData) GetETypeInfo2() (d ETypeInfo2, err error) {124 if pa.PADataType != patype.PA_ETYPE_INFO2 {125 err = fmt.Errorf("PAData does not contain PA EType Info 2 data. TypeID Expected: %v; Actual: %v", patype.PA_ETYPE_INFO2, pa.PADataType)126 return127 }128 _, err = asn1.Unmarshal(pa.PADataValue, &d)129 return130}...

Full Screen

Full Screen

unmarshal

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func main() {5 s := `[{"First":"James","Last":"Bond","Age":20},{"First":"Miss","Last":"Moneypenny","Age":19}]`6 bs := []byte(s)7 fmt.Printf("%T8 fmt.Printf("%T9 err := json.Unmarshal(bs, &people)10 if err != nil {11 fmt.Println(err)12 }13 fmt.Println("all of the data", people)14 for i, v := range people {15 fmt.Println("\nPERSON NUMBER", i)16 fmt.Println(v.First, v.Last, v.Age)17 }18}19import (20type Person struct {21}22func main() {23 p1 := Person{"James", "Bond", 20}24 p2 := Person{"Miss", "Moneypenny", 19}25 people := []Person{p1, p2}26 fmt.Println(people)27 bs, err := json.Marshal(people)28 if err != nil {29 fmt.Println(err)30 }31 fmt.Println(bs)32 fmt.Println(string(bs))33}

Full Screen

Full Screen

unmarshal

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func main() {5p1 := Person{"James", 20}6p2 := Person{"Moneypenny", 18}7people := []Person{p1, p2}8fmt.Println(people)9json.Unmarshal([]byte("people"), &people)10fmt.Println(people)11}12import (13type Person struct {14}15func main() {16p1 := Person{"James", 20}17p2 := Person{"Moneypenny", 18}18people := []Person{p1, p2}19fmt.Println(people)20byteArray, _ := json.Marshal(people)21fmt.Println(string(byteArray))22}23[{"Name":"James","Age":20},{"Name":"Moneypenny","Age":18}]

Full Screen

Full Screen

unmarshal

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func main() {5 jsonString := `{"Name":"John Doe","Age":30}`6 json.Unmarshal([]byte(jsonString), &p)7 fmt.Println(p.Name, p.Age)8}9import (10type Person struct {11}12func main() {13 p := Person{Name: "John Doe", Age: 30}14 jsonBytes, _ := json.Marshal(p)15 fmt.Println(string(jsonBytes))16}17{"Name":"John Doe","Age":30}18import (19type Person struct {20}21func main() {22 jsonString := `{"Name":"John Doe","Age":30}`23 json.Unmarshal([]byte(jsonString), &p)24 fmt.Println(p.Name, p.Age)25}26import (27type Person struct {28}29func main() {30 p := Person{Name: "John Doe", Age: 30}31 jsonBytes, _ := json.Marshal(p)32 fmt.Println(string(jsonBytes))33}34{"Name":"John Doe","Age":30}35import (36type Person struct {37}38func main() {39 jsonString := `{"Name":"John Doe","Age":30}`40 json.Unmarshal([]byte(jsonString), &p)41 fmt.Println(p.Name, p.Age)42}43import (44type Person struct {45}46func main() {47 p := Person{Name: "John Doe", Age: 30}

Full Screen

Full Screen

unmarshal

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func main() {5 jsonStr := `{"Name":"John", "Age":20, "Weight":70.5, "Married":true}`6 err := json.Unmarshal([]byte(jsonStr), &p)7 if err != nil {8 fmt.Println(err)9 }10 fmt.Printf("%+v", p)11}12{Name:John Age:20 Weight:70.5 Married:true}13import (14type Person struct {15}16func main() {17 p := Person{18 }19 jsonStr, err := json.Marshal(p)20 if err != nil {21 fmt.Println(err)22 }23 fmt.Println(string(jsonStr))24}25{"Name":"John","Age":20,"Weight":70.5,"Married":true}26MarshalIndent method converts a go value into a json string with a specified indent. To use this method, we have to import the encoding/json package. After importing the package, we have to pass the address of the value, prefix, and indent to the MarshalIndent method. The MarshalIndent method returns the byte slice of the json string and error value. If the error value is nil, it means that the method was executed successfully. If the error value is not nil, it means that there was an error while executing the method. In

Full Screen

Full Screen

unmarshal

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var data = []byte(`{"Name":"Alex","Age":20}`)4 err := json.Unmarshal(data, &v)5 if err != nil {6 fmt.Println("error:", err)7 }8 fmt.Printf("%+v", v)9}10import (11func main() {12 var data = []byte(`{"Name":"Alex","Age":20}`)13 err := json.Unmarshal(data, &v)14 if err != nil {15 fmt.Println("error:", err)16 }17 fmt.Printf("%+v", v)18}19import (20func main() {21 var data = []byte(`{"Name":"Alex","Age":20}`)22 err := json.Unmarshal(data, &v)23 if err != nil {24 fmt.Println("error:", err)25 }26 fmt.Printf("%+v", v)27}28import (29func main() {30 var data = []byte(`{"Name":"Alex","Age":20}`)31 err := json.Unmarshal(data, &v)32 if err != nil {33 fmt.Println("error:", err)34 }35 fmt.Printf("%+v", v)36}37import (38func main() {39 var data = []byte(`{"Name":"Alex","Age":20}`)40 err := json.Unmarshal(data, &v)41 if err != nil {42 fmt.Println("error:", err)43 }44 fmt.Printf("%+v", v)45}46import (47func main() {48 var data = []byte(`{"Name":"Alex","Age":20}`)49 err := json.Unmarshal(data, &v)50 if err != nil {51 fmt.Println("error:", err)52 }53 fmt.Printf("%

Full Screen

Full Screen

unmarshal

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 file, e := ioutil.ReadFile("test.json")4 if e != nil {5 fmt.Printf("File error: %v6 os.Exit(1)7 }8 fmt.Printf("%s9", string(file))10 var dat map[string]interface{}11 if err := json.Unmarshal(file, &dat); err != nil {12 panic(err)13 }14 fmt.Println(dat)15}16import (17func main() {18 file, e := ioutil.ReadFile("test.json")19 if e != nil {20 fmt.Printf("File error: %v21 os.Exit(1)22 }23 fmt.Printf("%s24", string(file))25 var dat map[string]interface{}26 if err := json.Unmarshal(file, &dat); err != nil {27 panic(err)28 }29 fmt.Println(dat)30}31import (32func main() {33 file, e := ioutil.ReadFile("test.json")34 if e != nil {35 fmt.Printf("File error: %v36 os.Exit(1)37 }38 fmt.Printf("%s39", string(file))40 var dat map[string]interface{}41 if err := json.Unmarshal(file, &dat); err != nil {42 panic(err)43 }44 fmt.Println(dat)45}46import (47func main() {48 file, e := ioutil.ReadFile("test.json")49 if e != nil {50 fmt.Printf("File error: %v51 os.Exit(1)52 }53 fmt.Printf("%s54", string(file))

Full Screen

Full Screen

unmarshal

Using AI Code Generation

copy

Full Screen

1import (2type Student struct {3}4func main() {5 jsonString := `{"Name":"John","Age":23}`6 err := json.Unmarshal([]byte(jsonString), &s)7 if err != nil {8 fmt.Println(err)9 }10 fmt.Println(s)11}12{John 23}13import (14func main() {15 var m map[string]interface{}16 jsonString := `{"Name":"John","Age":23}`17 err := json.Unmarshal([]byte(jsonString), &m)18 if err != nil {19 fmt.Println(err)20 }21 fmt.Println(m)22}23import (24func main() {25 var s []interface{}26 jsonString := `[{"Name":"John","Age":23},{"Name":"Mary","Age":24}]`27 err := json.Unmarshal([]byte(jsonString), &s)28 if err != nil {29 fmt.Println(err)30 }31 fmt.Println(s)32}33[{John 23} {Mary 24}]34import (35type Student struct {36}37func main() {38 s := Student{Name: "

Full Screen

Full Screen

unmarshal

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 jsonString := `{"id": 1, "name": "John", "age": 30, "address": "New York"}`4 var result map[string]interface{}5 json.Unmarshal([]byte(jsonString), &result)6 fmt.Println(result)7}8import (9type Person struct {10}11func main() {12 jsonString := `{"id": 1, "name": "John", "age": 30, "address": "New York"}`13 json.Unmarshal([]byte(jsonString), &result)14 fmt.Println(result)15}16{1 John 30 New York}17import (18type Person struct {19}20func main() {21 jsonString := `{"id": 1, "name": "John", "age": 30, "address": "New York"}`22 var result map[string]interface{}23 json.Unmarshal([]byte(jsonString), &result)24 fmt.Println(result["id"])25 fmt.Println(result["name"])26 fmt.Println(result["age"])27 fmt.Println(result["address"])28}29import (30type Person struct {31}32func main() {

Full Screen

Full Screen

unmarshal

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func main() {5 jsonString := `{"Name":"John", "Age":30}`6 json.Unmarshal([]byte(jsonString), &person)7 fmt.Println(person)8}9{John 30}10json.Marshal(v interface{}) ([]byte, error)11import (12type Person struct {13}14func main() {15 person := Person{"John", 30}16 jsonString, err := json.Marshal(person)17 if err != nil {18 fmt.Println(err)19 }20 fmt.Println(string(jsonString))21}22{"Name":"John","Age":30}23func (d *Decoder) Unmarshal(v interface{}) error24import (25type Person struct {26}27func main() {28 jsonString := `{"Name":"John", "Age":30}`

Full Screen

Full Screen

unmarshal

Using AI Code Generation

copy

Full Screen

1err := json.Unmarshal(body, &p)2if err != nil {3 log.Fatal(err)4}5fmt.Println(p)6var p interface{}7err := json.Unmarshal(body, &p)8if err != nil {9 log.Fatal(err)10}11fmt.Println(p)12var p interface{}13err := json.Unmarshal(body, &p)14if err != nil {15 log.Fatal(err)16}17fmt.Println(p)18var p interface{}19err := json.Unmarshal(body, &p)20if err != nil {21 log.Fatal(err)22}23fmt.Println(p)24var p interface{}25err := json.Unmarshal(body, &p)26if err != nil {27 log.Fatal(err)28}29fmt.Println(p)30var p interface{}31err := json.Unmarshal(body, &p)32if err != nil {33 log.Fatal(err)34}35fmt.Println(p)

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful