How to write a vectorHow to efficiently concatenate strings in Go?How to read/write from/to file using Go?How to check if a map contains a key in Go?How do you write multiline strings in Go?golang slice in mysql query with where in clauseFetch records with query Args in Goconvert interface directly to int in Golang, where interface stores a number as stringHow to add an already serialized bytebuffer to a builder that is creating a vector of tables?Is it possible to optimize flatbuffers serialization when constructing from native C++ structs?

Employee is self-centered and affects the team negatively

Add EnvironmentPurpose to existing TtmCdTopologyType

What is a good way to allow only one non null field in an object

Not taking the bishop by the knight, why?

Which types of fruit can I give to my dog?

Rusty Chain and back cassette – Replace or Repair?

What are my options legally if NYC company is not paying salary?

Do Monks gain the 9th level Unarmored Movement benefit when wearing armor or using a shield?

What's the "magic similar to the Knock spell" referenced in the Dungeon of the Mad Mage adventure?

What dice to use in a game that revolves around triangles?

How to start your Starcraft II games vs AI immediately?

Why does the electron wavefunction not collapse within atoms at room temperature in gas, liquids or solids due to decoherence?

Can you turn a recording upside-down?

Locked my sa user out

How to get MAX value using SOQL when there are more than 50,000 rows

What can cause an unfrozen indoor copper drain pipe to crack?

Why is there a cap on 401k contributions?

Logo selection for poster presentation

Why use steam instead of just hot air?

Was Mohammed the most popular first name for boys born in Berlin in 2018?

Fee negotiations in Lightning

I might have messed up in the 'Future Work' section of my thesis

Is it a Munchausen Number?

Which spells are in some way related to shadows or the Shadowfell?



How to write a vector


How to efficiently concatenate strings in Go?How to read/write from/to file using Go?How to check if a map contains a key in Go?How do you write multiline strings in Go?golang slice in mysql query with where in clauseFetch records with query Args in Goconvert interface directly to int in Golang, where interface stores a number as stringHow to add an already serialized bytebuffer to a builder that is creating a vector of tables?Is it possible to optimize flatbuffers serialization when constructing from native C++ structs?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I am using the Go flatbuffers interface for the first time. I find the instructions sparse.



I would like to write a vector of uint64s into a table. Ideally, I would like to store numbers directly in a vector without knowing how many there are up front (I'm reading them from sql.Rows iterator). I see the generated code for the table has functions:



func DatasetGridAddDates(builder *flatbuffers.Builder, dates flatbuffers.UOffsetT) 
builder.PrependUOffsetTSlot(2, flatbuffers.UOffsetT(dates), 0)

func DatasetGridStartDatesVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT
return builder.StartVector(8, numElems, 8)



Can I first write the vector using (??), then use DatasetGridAddDates to record the resulting vector in the containing "DatasetGrid" table?










share|improve this question






























    2















    I am using the Go flatbuffers interface for the first time. I find the instructions sparse.



    I would like to write a vector of uint64s into a table. Ideally, I would like to store numbers directly in a vector without knowing how many there are up front (I'm reading them from sql.Rows iterator). I see the generated code for the table has functions:



    func DatasetGridAddDates(builder *flatbuffers.Builder, dates flatbuffers.UOffsetT) 
    builder.PrependUOffsetTSlot(2, flatbuffers.UOffsetT(dates), 0)

    func DatasetGridStartDatesVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT
    return builder.StartVector(8, numElems, 8)



    Can I first write the vector using (??), then use DatasetGridAddDates to record the resulting vector in the containing "DatasetGrid" table?










    share|improve this question


























      2












      2








      2


      0






      I am using the Go flatbuffers interface for the first time. I find the instructions sparse.



      I would like to write a vector of uint64s into a table. Ideally, I would like to store numbers directly in a vector without knowing how many there are up front (I'm reading them from sql.Rows iterator). I see the generated code for the table has functions:



      func DatasetGridAddDates(builder *flatbuffers.Builder, dates flatbuffers.UOffsetT) 
      builder.PrependUOffsetTSlot(2, flatbuffers.UOffsetT(dates), 0)

      func DatasetGridStartDatesVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT
      return builder.StartVector(8, numElems, 8)



      Can I first write the vector using (??), then use DatasetGridAddDates to record the resulting vector in the containing "DatasetGrid" table?










      share|improve this question
















      I am using the Go flatbuffers interface for the first time. I find the instructions sparse.



      I would like to write a vector of uint64s into a table. Ideally, I would like to store numbers directly in a vector without knowing how many there are up front (I'm reading them from sql.Rows iterator). I see the generated code for the table has functions:



      func DatasetGridAddDates(builder *flatbuffers.Builder, dates flatbuffers.UOffsetT) 
      builder.PrependUOffsetTSlot(2, flatbuffers.UOffsetT(dates), 0)

      func DatasetGridStartDatesVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT
      return builder.StartVector(8, numElems, 8)



      Can I first write the vector using (??), then use DatasetGridAddDates to record the resulting vector in the containing "DatasetGrid" table?







      go flatbuffers






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 8:24









      Flimzy

      41.2k1367102




      41.2k1367102










      asked Mar 23 at 5:34









      shauncshaunc

      2,8312039




      2,8312039






















          1 Answer
          1






          active

          oldest

          votes


















          4














          (caveat: I have not heard of FlatBuffers prior to reading your question)



          If you do know the length in advance, storing a vector is done as explained in the tutorial:



          name := builder.CreateString("hello")

          q55310927.DatasetGridStartDatesVector(builder, len(myDates))
          for i := len(myDates) - 1; i >= 0; i--
          builder.PrependUint64(myDates[i])

          dates := builder.EndVector(len(myDates))

          q55310927.DatasetGridStart(builder)
          q55310927.DatasetGridAddName(builder, name)
          q55310927.DatasetGridAddDates(builder, dates)
          grid := q55310927.DatasetGridEnd(builder)
          builder.Finish(grid)


          Now what if you don’t have len(myDates)? On a toy example I get exactly the same output if I replace StartDatesVector(builder, len(myDates)) with StartDatesVector(builder, 0). Looking at the source code, it seems like the numElems may be necessary for alignment and for growing the buffer. I imagine alignment might be moot when you’re dealing with uint64, and growing seems to happen automatically on PrependUint64, too.



          So, try doing it without numElems:



          q55310927.DatasetGridStartDatesVector(builder, 0)
          var n int
          for rows.Next() // use ORDER BY to make them go in reverse order
          var date uint64
          if err := rows.Scan(&date); err != nil
          // ...

          builder.PrependUint64(date)
          n++

          dates := builder.EndVector(n)


          and see if it works on your data.






          share|improve this answer

























          • Thanks! .. provisionally marked as answer, though more authoritative information concerning not knowing length in advance would be useful.

            – shaunc
            Mar 23 at 17:25











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310927%2fhow-to-write-a-vector%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4














          (caveat: I have not heard of FlatBuffers prior to reading your question)



          If you do know the length in advance, storing a vector is done as explained in the tutorial:



          name := builder.CreateString("hello")

          q55310927.DatasetGridStartDatesVector(builder, len(myDates))
          for i := len(myDates) - 1; i >= 0; i--
          builder.PrependUint64(myDates[i])

          dates := builder.EndVector(len(myDates))

          q55310927.DatasetGridStart(builder)
          q55310927.DatasetGridAddName(builder, name)
          q55310927.DatasetGridAddDates(builder, dates)
          grid := q55310927.DatasetGridEnd(builder)
          builder.Finish(grid)


          Now what if you don’t have len(myDates)? On a toy example I get exactly the same output if I replace StartDatesVector(builder, len(myDates)) with StartDatesVector(builder, 0). Looking at the source code, it seems like the numElems may be necessary for alignment and for growing the buffer. I imagine alignment might be moot when you’re dealing with uint64, and growing seems to happen automatically on PrependUint64, too.



          So, try doing it without numElems:



          q55310927.DatasetGridStartDatesVector(builder, 0)
          var n int
          for rows.Next() // use ORDER BY to make them go in reverse order
          var date uint64
          if err := rows.Scan(&date); err != nil
          // ...

          builder.PrependUint64(date)
          n++

          dates := builder.EndVector(n)


          and see if it works on your data.






          share|improve this answer

























          • Thanks! .. provisionally marked as answer, though more authoritative information concerning not knowing length in advance would be useful.

            – shaunc
            Mar 23 at 17:25















          4














          (caveat: I have not heard of FlatBuffers prior to reading your question)



          If you do know the length in advance, storing a vector is done as explained in the tutorial:



          name := builder.CreateString("hello")

          q55310927.DatasetGridStartDatesVector(builder, len(myDates))
          for i := len(myDates) - 1; i >= 0; i--
          builder.PrependUint64(myDates[i])

          dates := builder.EndVector(len(myDates))

          q55310927.DatasetGridStart(builder)
          q55310927.DatasetGridAddName(builder, name)
          q55310927.DatasetGridAddDates(builder, dates)
          grid := q55310927.DatasetGridEnd(builder)
          builder.Finish(grid)


          Now what if you don’t have len(myDates)? On a toy example I get exactly the same output if I replace StartDatesVector(builder, len(myDates)) with StartDatesVector(builder, 0). Looking at the source code, it seems like the numElems may be necessary for alignment and for growing the buffer. I imagine alignment might be moot when you’re dealing with uint64, and growing seems to happen automatically on PrependUint64, too.



          So, try doing it without numElems:



          q55310927.DatasetGridStartDatesVector(builder, 0)
          var n int
          for rows.Next() // use ORDER BY to make them go in reverse order
          var date uint64
          if err := rows.Scan(&date); err != nil
          // ...

          builder.PrependUint64(date)
          n++

          dates := builder.EndVector(n)


          and see if it works on your data.






          share|improve this answer

























          • Thanks! .. provisionally marked as answer, though more authoritative information concerning not knowing length in advance would be useful.

            – shaunc
            Mar 23 at 17:25













          4












          4








          4







          (caveat: I have not heard of FlatBuffers prior to reading your question)



          If you do know the length in advance, storing a vector is done as explained in the tutorial:



          name := builder.CreateString("hello")

          q55310927.DatasetGridStartDatesVector(builder, len(myDates))
          for i := len(myDates) - 1; i >= 0; i--
          builder.PrependUint64(myDates[i])

          dates := builder.EndVector(len(myDates))

          q55310927.DatasetGridStart(builder)
          q55310927.DatasetGridAddName(builder, name)
          q55310927.DatasetGridAddDates(builder, dates)
          grid := q55310927.DatasetGridEnd(builder)
          builder.Finish(grid)


          Now what if you don’t have len(myDates)? On a toy example I get exactly the same output if I replace StartDatesVector(builder, len(myDates)) with StartDatesVector(builder, 0). Looking at the source code, it seems like the numElems may be necessary for alignment and for growing the buffer. I imagine alignment might be moot when you’re dealing with uint64, and growing seems to happen automatically on PrependUint64, too.



          So, try doing it without numElems:



          q55310927.DatasetGridStartDatesVector(builder, 0)
          var n int
          for rows.Next() // use ORDER BY to make them go in reverse order
          var date uint64
          if err := rows.Scan(&date); err != nil
          // ...

          builder.PrependUint64(date)
          n++

          dates := builder.EndVector(n)


          and see if it works on your data.






          share|improve this answer















          (caveat: I have not heard of FlatBuffers prior to reading your question)



          If you do know the length in advance, storing a vector is done as explained in the tutorial:



          name := builder.CreateString("hello")

          q55310927.DatasetGridStartDatesVector(builder, len(myDates))
          for i := len(myDates) - 1; i >= 0; i--
          builder.PrependUint64(myDates[i])

          dates := builder.EndVector(len(myDates))

          q55310927.DatasetGridStart(builder)
          q55310927.DatasetGridAddName(builder, name)
          q55310927.DatasetGridAddDates(builder, dates)
          grid := q55310927.DatasetGridEnd(builder)
          builder.Finish(grid)


          Now what if you don’t have len(myDates)? On a toy example I get exactly the same output if I replace StartDatesVector(builder, len(myDates)) with StartDatesVector(builder, 0). Looking at the source code, it seems like the numElems may be necessary for alignment and for growing the buffer. I imagine alignment might be moot when you’re dealing with uint64, and growing seems to happen automatically on PrependUint64, too.



          So, try doing it without numElems:



          q55310927.DatasetGridStartDatesVector(builder, 0)
          var n int
          for rows.Next() // use ORDER BY to make them go in reverse order
          var date uint64
          if err := rows.Scan(&date); err != nil
          // ...

          builder.PrependUint64(date)
          n++

          dates := builder.EndVector(n)


          and see if it works on your data.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 23 at 8:21

























          answered Mar 23 at 8:16









          Vasiliy FaronovVasiliy Faronov

          9,07812735




          9,07812735












          • Thanks! .. provisionally marked as answer, though more authoritative information concerning not knowing length in advance would be useful.

            – shaunc
            Mar 23 at 17:25

















          • Thanks! .. provisionally marked as answer, though more authoritative information concerning not knowing length in advance would be useful.

            – shaunc
            Mar 23 at 17:25
















          Thanks! .. provisionally marked as answer, though more authoritative information concerning not knowing length in advance would be useful.

          – shaunc
          Mar 23 at 17:25





          Thanks! .. provisionally marked as answer, though more authoritative information concerning not knowing length in advance would be useful.

          – shaunc
          Mar 23 at 17:25



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310927%2fhow-to-write-a-vector%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해